From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by dpdk.org (Postfix) with ESMTP id 516D42C72 for ; Thu, 2 Jun 2016 05:30:06 +0200 (CEST) Received: by mail-pa0-f51.google.com with SMTP id um11so2070008pab.0 for ; Wed, 01 Jun 2016 20:30:06 -0700 (PDT) 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=XPIDsgxaRq47usYptLZHOFCLEh2xaGGyK9/gZ3nOl7c=; b=OcPiiCIoR3BMUFnSJG9BiXdKunsrSDHr6DMBBrDWoPZPr2RqCOqYvgmsZBPQoVymr0 YHwGT64TwSwVEJcTBJG72nakAdvHVAqTmcFWt4aNGCvGokRWGsRSsiloKHIqxYf3k65D z2a0saDeerKCxfxMlYDw5VePPOEDLI6BhlOEqoucBgjA03Yslhg78WLlviphtgpU1V0i /bLbfCMh1o557P1Uoeci/8mXRuImgihQHUixncWgfenZXkosRDPuIdUmiWFhWHXeGmH0 1tVJ/3qqoXlfkMg9x7RDDnBTlZ3dAaDuKuoTWna8Vq8fXwzxeZ6iFNKgAa5J9gATR4Rb zWRw== 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=XPIDsgxaRq47usYptLZHOFCLEh2xaGGyK9/gZ3nOl7c=; b=G+6etu8gbOfM9ap0PBmfWnvup8mPukOBMEg5XlTikFGLyPsZDoG13wu+8EDKwJemHo ptiJpJeq+bBMt/ZdU+mkf+EzGBFPJIbjMRZ9VREoRSxfX8G388fSGl7bEn7i99C30CNp qHZCQ9SC8sfrS0zMA5mVp1tvM3P/k7ovhTgJ35tOA563y5z+28fdXXZi7E9ZWxf0WKCo YZjLI/EJlsByqNEaKyG+Hx0NdctGNOOIjRtS9//j2Y0If+o0Uey+9MyvlLzBTjCu0QDH F4PpHfukkYhlTQ8dGjTeapgh4UzPQdJkUgeP/6eSCgC0pIyFt8vXB31Va2q1SgJVECM1 zr1A== X-Gm-Message-State: ALyK8tKG9n3TGVmtYJ0nHBhNOxGx6UA0s52u9bBPaqXRd8aVnvH9Lj0InD0IlqXhrT2O1w== X-Received: by 10.66.139.108 with SMTP id qx12mr2390470pab.27.1464838205561; Wed, 01 Jun 2016 20:30:05 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id th5sm59830828pab.31.2016.06.01.20.30.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Jun 2016 20:30:04 -0700 (PDT) From: Tetsuya Mukawa To: dev@dpdk.org Cc: yuanhan.liu@linux.intel.com, jianfeng.tan@intel.com, huawei.xie@intel.com, Tetsuya Mukawa Date: Thu, 2 Jun 2016 12:29:43 +0900 Message-Id: <1464838185-21751-5-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1464838185-21751-1-git-send-email-mukawa@igel.co.jp> References: <1464838185-21751-1-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1457512409-24403-12-git-send-email-mukawa@igel.co.jp> References: <1457512409-24403-12-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v5 4/6] 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: Thu, 02 Jun 2016 03:30:06 -0000 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 --- 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