From 39bef5cb98aab92cd6be69929b183854ccdb0f39 Mon Sep 17 00:00:00 2001 From: Santosh Shukla Date: Fri, 6 Oct 2017 16:33:41 +0530 Subject: [PATCH] bus: get IOMMU class API(rte_bus_get_iommu_class) helps to automatically detect and select appropriate iova mapping scheme for iommu capable device on that bus. Algorithm for iova scheme selection for bus: 0. Iterate through bus_list. 1. Collect each bus iova mode value and update into 'mode' var. 2. Mode selection scheme is: if mode == 0 then iova mode is _pa, if mode == 1 then iova mode is _pa, if mode == 2 then iova mode is _va, if mode == 3 then iova mode ia _pa. So mode !=2 will be default iova mode (_pa). Signed-off-by: Santosh Shukla Signed-off-by: Jerin Jacob Reviewed-by: Maxime Coquelin Reviewed-by: Anatoly Burakov Acked-by: Hemant Agrawal Tested-by: Hemant Agrawal --- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 1 + lib/librte_eal/common/eal_common_bus.c | 23 +++++++++++++++++ lib/librte_eal/common/eal_common_pci.c | 1 + lib/librte_eal/common/include/rte_bus.h | 25 +++++++++++++++++++ .../linuxapp/eal/rte_eal_version.map | 1 + 5 files changed, 51 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index f8724bd5d7..e887e065c8 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -242,6 +242,7 @@ EXPERIMENTAL { DPDK_17.11 { global: + rte_bus_get_iommu_class; rte_pci_get_iommu_class; rte_pci_match; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 08bec2d931..a30a8982ed 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -222,3 +222,26 @@ rte_bus_find_by_device_name(const char *str) c[0] = '\0'; return rte_bus_find(NULL, bus_can_parse, name); } + + +/* + * Get iommu class of devices on the bus. + */ +enum rte_iova_mode +rte_bus_get_iommu_class(void) +{ + int mode = RTE_IOVA_DC; + struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + + if (bus->get_iommu_class) + mode |= bus->get_iommu_class(); + } + + if (mode != RTE_IOVA_VA) { + /* Use default IOVA mode */ + mode = RTE_IOVA_PA; + } + return mode; +} diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 3b7d0a0ee3..0f0e4b93bf 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -564,6 +564,7 @@ struct rte_pci_bus rte_pci_bus = { .plug = pci_plug, .unplug = pci_unplug, .parse = pci_parse, + .get_iommu_class = rte_pci_get_iommu_class, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 2501fa26da..6fb08341ab 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -183,6 +183,20 @@ struct rte_bus_conf { enum rte_bus_scan_mode scan_mode; /**< Scan policy. */ }; + +/** + * Get common iommu class of the all the devices on the bus. The bus may + * check that those devices are attached to iommu driver. + * If no devices are attached to the bus. The bus may return with don't care + * (_DC) value. + * Otherwise, The bus will return appropriate _pa or _va iova mode. + * + * @return + * enum rte_iova_mode value. + */ +typedef enum rte_iova_mode (*rte_bus_get_iommu_class_t)(void); + + /** * A structure describing a generic bus. */ @@ -196,6 +210,7 @@ struct rte_bus { rte_bus_unplug_t unplug; /**< Remove single device from driver */ rte_bus_parse_t parse; /**< Parse a device name */ struct rte_bus_conf conf; /**< Bus configuration */ + rte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */ }; /** @@ -295,6 +310,16 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev); */ struct rte_bus *rte_bus_find_by_name(const char *busname); + +/** + * Get the common iommu class of devices bound on to buses available in the + * system. The default mode is PA. + * + * @return + * enum rte_iova_mode value. + */ +enum rte_iova_mode rte_bus_get_iommu_class(void); + /** * Helper for Bus registration. * The constructor has higher priority than PMD constructors. diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 95756e268a..0f04b0ad2e 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -247,6 +247,7 @@ EXPERIMENTAL { DPDK_17.11 { global: + rte_bus_get_iommu_class; rte_pci_get_iommu_class; rte_pci_match; -- 2.20.1