From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f179.google.com (mail-pf0-f179.google.com [209.85.192.179]) by dpdk.org (Postfix) with ESMTP id 1907E4CE4 for ; Wed, 9 Mar 2016 09:34:04 +0100 (CET) Received: by mail-pf0-f179.google.com with SMTP id 129so34723890pfw.1 for ; Wed, 09 Mar 2016 00:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ioS2oYLvVjj3vRDYH60l+wEC4cYaa4YZdttbBLHqITw=; b=ylgh1YrqxOwul48zVyFUJw22cPe656CBBj0W4g+39EZ1YUNRasdzUdCnulOOs5ujj/ QaxUq/v8Ove2IKZnI5v3dMS3FcyJSwhof8fkKN8y8KKRYa17N1uOfGDdEUP0DruiZYHF 553273LWyszTHzGWR/2K1hjUIbuplkUxIJUhKYX3ZLZnl/rt7gGs+pgLjjES/3fH0C4z ccd2U0R3eJc2IMuw005CzOPccmI4QpGYXL/g+4wT8GCsXiRGurVDtGF+6v03ffY0z0un Qh2GKt3+Ixdv4fhztRMdAO1LpwX0xMHr2qFSCDZu65vf5ctX/aric4ko0ZXjtH4rkyp3 Zj0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ioS2oYLvVjj3vRDYH60l+wEC4cYaa4YZdttbBLHqITw=; b=WMJ9/WQoSSiGMpiLA6kKQxk+D2Nr3+OnoeM6H1dbn4J1xuekAlAqpzQNZiUqH3bZaL frUYKuXUnBXcb8/y/WFjPUXKlUgyKHDGGvG+F5pMeoQsaA0Da/pWC5xuE3UMr8b7Zk7p NwJ5PdpLkhF3nEBZk6TEkLWlcrprgVPm/LtOwpA4HTryRPa519TdLSL+LB2YcBqsJ2K/ A9zFrG3f/uI0v2kebCdG6C8HFB0FS5cuM3vOLxErTiUSA2w9yrUYQ04u7HXGcVwLaPC/ rnA1s3xJH68q4yos6A+AhpRYX31EKsEmWf26UXRxEQO7/6KXWIkFo3a3TkUW+j3xsBXu SMCA== X-Gm-Message-State: AD7BkJJzdqUsJahnWvgLO0Mn7rVegQ4o3z/SVYwBK0KQbIBXV0NXSk2Oof2cmbaqnSaQmQ== X-Received: by 10.98.9.92 with SMTP id e89mr48690987pfd.34.1457512443550; Wed, 09 Mar 2016 00:34:03 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id qh8sm10350238pac.40.2016.03.09.00.34.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Mar 2016 00:34:02 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org, jianfeng.tan@intel.com, huawei.xie@intel.com, yuanhan.liu@linux.intel.com Date: Wed, 9 Mar 2016 17:33:26 +0900 Message-Id: <1457512409-24403-10-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457512409-24403-1-git-send-email-mukawa@igel.co.jp> References: <1457512409-24403-1-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1456129075-14909-4-git-send-email-mukawa@igel.co.jp> References: <1456129075-14909-4-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v4 09/12] virtio, qtest: Add misc functions to handle pci information X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2016 08:34:04 -0000 The patch adds below functions. - qtest_read_pci_cfg - qtest_get_bar - 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 --- drivers/net/virtio/qtest_utils.c | 77 ++++++++++++++++++++++++++++++++++++++++ drivers/net/virtio/qtest_utils.h | 56 +++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/drivers/net/virtio/qtest_utils.c b/drivers/net/virtio/qtest_utils.c index 337546a..55ed504 100644 --- a/drivers/net/virtio/qtest_utils.c +++ b/drivers/net/virtio/qtest_utils.c @@ -427,6 +427,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\n", 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\n", bar); + return NULL; + } + + dev = qtest_find_device(s, name); + if (dev == NULL) { + PMD_DRV_LOG(ERR, "Cannot find specified device: %s\n", name); + return NULL; + } + + if (dev->bar[bar].type == QTEST_PCI_BAR_DISABLE) { + PMD_DRV_LOG(ERR, "Cannot find valid BAR(%s): %u\n", 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; +} + int qtest_intr_enable(struct qtest_session *s) { diff --git a/drivers/net/virtio/qtest_utils.h b/drivers/net/virtio/qtest_utils.h index 0717ee9..dfd2b03 100644 --- a/drivers/net/virtio/qtest_utils.h +++ b/drivers/net/virtio/qtest_utils.h @@ -270,6 +270,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 piix3 device. * * @param s -- 2.1.4