From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0064.outbound.protection.outlook.com [104.47.33.64]) by dpdk.org (Postfix) with ESMTP id 2D517FA63 for ; Wed, 18 Jan 2017 15:03:46 +0100 (CET) Received: from DM2PR03CA0010.namprd03.prod.outlook.com (10.141.96.20) by MWHPR03MB2479.namprd03.prod.outlook.com (10.169.200.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.860.13; Wed, 18 Jan 2017 14:03:45 +0000 Received: from BN1AFFO11FD031.protection.gbl (2a01:111:f400:7c10::124) by DM2PR03CA0010.outlook.office365.com (2a01:111:e400:2428::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.860.13 via Frontend Transport; Wed, 18 Jan 2017 14:03:45 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD031.mail.protection.outlook.com (10.58.52.185) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.803.8 via Frontend Transport; Wed, 18 Jan 2017 14:03:44 +0000 Received: from tophie.ap.freescale.net ([10.232.14.39]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v0IE2512026776; Wed, 18 Jan 2017 07:03:43 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Wed, 18 Jan 2017 19:35:24 +0530 Message-ID: <1484748329-5418-9-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484748329-5418-1-git-send-email-shreyansh.jain@nxp.com> References: <1484735880-17178-1-git-send-email-shreyansh.jain@nxp.com> <1484748329-5418-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131292218247435939; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(7916002)(39850400002)(39410400002)(39380400002)(39840400002)(39860400002)(39450400003)(39400400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(8676002)(110136003)(5660300001)(2950100002)(36756003)(97736004)(5003940100001)(105606002)(92566002)(6666003)(86362001)(85426001)(626004)(38730400001)(33646002)(50466002)(77096006)(53936002)(6916009)(106466001)(48376002)(50986999)(81166006)(104016004)(2351001)(2906002)(305945005)(4326007)(575784001)(8656002)(356003)(76176999)(189998001)(47776003)(81156014)(54906002)(50226002)(8936002)(68736007); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2479; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD031; 1:diMSCh/rRzyWaaPwb+C3QP+nZwjWI9ft9ajZ8pLNuVVUVQrL7Ml5upyX1Xsqs9mXrppWwvP8Qbc6FgisJ1IK8DpP++u9BdADUsfdCtrZTLjVX+onwOcw8hSzYzBj+oOSVTxwZb6cMyYfTjnHrtnk5NqiRSwUoeni6wYCfUF/zMKm8+s4W6rpv9xSkO2Xw4rU7ebHTxhtyScQzyRqv1x57AelKnytpwD5SHvldZZUVOS85eEFCOOjRJ83XfbulNRFOSVZQ5YQjdZB12BCM6jeJDovUqhOQJBWDC+wyHLfA+ZEYL3eSZ2sBE1RbAcb44yuEzr/53Ea3otJyu4dyaujJGeYOon/YDfpAAV5MSNR/mMvmTImbbCYM/N8Il3VO94LyiAH82m0VTOLechy91hFmIxf3Zw+UQ5nFreNiIuEbXEKT/zUckX5677LPdkMKYoFPPcdV2r9zdZbdmUCHlMlPMOnjsQnk18MKnRZs/4bM1bQANBFLrjR0679Be1clOdC+XXxfzjnLYbwwfDNxGVuR57V52io+yIPQIkSdeHhlCGDlJEHXg3ckLRUneNVfUDVH2vDrY+/Prt1f5VpogzujyHhMR9+G7kgrd8yjjpTCMecKFCdZ0ZRuOsliXRlS/VyPURpBwMQwAdo28aPPs16DHTBfzM9wnj4P+i+BslTuufzPQsQyI9MUZvOnnECff/GzJVR+Q0wmpmRubDYTYBSbg== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 716b3483-e367-46fe-56a3-08d43faad0e0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:MWHPR03MB2479; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 3:oJPBYFpLRuj9P5vBb4JmqQwRoMQzXg9wZR4PGqRNHLZICFPUXK9wQN4RKqYB3QPB1+DNvHjfASJJomi/96pEgqzLubQP0bDfj5aNw7rlsBY6/PZh3bqiA7Sd8JlxABO2L9qmy7bkBzasuBA1s9maeBgskCBT2CoxbXD4vXXQLx7VQAFF+KoFmLHn/qyI64yEPnShyafMziBPv0LR25qqVpmZ/v2fK+CgwQliOvdE75mbyYtpS8AEiZ6mF8Wif6oUSSNcXzBoHHAn9blkd++5HdIE98UAHIOW/Di8sX7JY7A0Hvjt6cv0S5/BOaL9OTSHr+a9UXJJQx94ES2GLYj0blB7f1ifz28svMD/C3e87PfNZYAjaGh7XTwANPAyIDrw X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 25:+cjgEk7vFgq6ESzQV5oBfHJBjMRvF3ixLAQWGldKioS4J7woWWE3P7cQMBVAZlCk1M9DAda+ZRQPPkjlwJM5BL35BtxigdOsIBMdY62IiiEXpgvLuJg3LDPJowS+jpIkd8+MdNb7LXJ0tJJ1t4Gb2MO3YE/pXuKxFeyXuKfhd3Q1EYNrLA8hWHuYRJOr/KQN3lKVNHs5IA9uh26K0IujtRPII8fyP8iGORh0ovzZsJH/OIM8Xd6sWxdQepySCV+U1+LnimK5i5ddmpEsyCchS4GpIzSoYs9+a8AxQcqFSbFklxMzL9EPcJ2Ykp72j4QozmJ55xk+ML15cXoM0HwDlJGB1wVtgbM+4Gz4Mm8RaqEQIahvlzwWyZgqK6n3iLLBjsyq+MmFat7wKuYA2iuKmWaLMnVn+3vRfBGnK06zh1RQFiCM8ncR+3GbMhJeYGXJB5cs/2V9nH8JuwVyjKvvbRTyDvcwPtnobfxsGLXSOuyHLs0hcBQaxLkW7BxBlGp6BQpLumpaHQMC7agAlp1h/w0Qq/6F6M6nCEVOgdOnb4VsGucez32kNqXQIYckIHZ5FTObeWC+JPoLZZC6z3qg34S4lyvAp9GVzXugvMLmPcVRbGTxv3QBEtVydymuz3C0ew3KvxU/lMrdaMS9MeLJkLoib+YoitWgiaxo7PXaoqsDoB8lGrpa/p2QbkB6mwwQq+G0gkv8MyEXghwvpdPQctGDZRIWW2q1EpQzN5/t8G1CBZpwBjpBLII8SlxOuvK0XmV9PoZQ/knGvVIQk0NQjQ== X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 31:fKRyAaMHXJEVeB6MjNm7zgL9PXtD7pmBuPUph+jhjlosNJW/kamMvvH5lznmL70xwPcjRCeovZsHjukcX20W211FXtztq+x9qbvMCyxR31rMtGEmrLz/VxFt0FEH8RAg2o2cLGgiF9kic9i/1QHuau30GmX2CMwFWfxi8brBzUEUfaDSVGiFWCCspmEZPwXSDshqMOrBKSkfk1LSV/00bQ9aD0QUhTA3pJym1ZBn5L+1j8zDiQdCsKuTrxpxh6B6Vf7+TyRCIs0ezMlktk3tBw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(13015025)(13018025)(13017025)(13023025)(13024025)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6096035)(20161123561025)(20161123556025)(20161123563025)(20161123565025)(20161123559025); SRVR:MWHPR03MB2479; BCL:0; PCL:0; RULEID:(400006); SRVR:MWHPR03MB2479; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 4:Xy2B7lkh6J9kbSzPX+4KQ851yw6ACgnXnRTlI+Zvx36XnamT8l65xfnBHclIVMZfRaMORfE6Mg9UJ0g0SVy4Th2eITju6PqvUAaB+XFSInZyqlPh1yi7K2+1vpfOTtfRL4MMYwra3dTIydT+BP6ZKxjlh1CFeFmFVX2Ec3ThepgjOIoUQ7iU1J98gsy2jwXRJQKsQXLRjdc7YGEM9JljzjVLf3O7yzCBqt6vX+Zbq+LfCAfyuHLnbYo3K093heyzrcEsMEkrJ8uYxTkVv0OnEHwk+K+uD/Qser57zNUZ4+5OvF6BsDgZnPwCamceZ2InSgh3jsq5mKRZbqVqcHgcaoIv41clBzYSU9DSGY2s7P53yP/bArLs/Ke+KTI7tfXRYAO43I5BhLxXFLCs6p3x+1vq7400a1oZJwMSj5uBpgdLa126hdJ2hYg0dXta/rMViWFG38jqLZCWvwOap0x6of02crLx8kksaicy6ynv5v/BNr0jlTk1c2Nd9ltHtMVKbezxDXBYpDZcd9APdc+je/30kV8cQKc5xqHO9OcfReM4Lnz4w+1rNufEthP76ZXW67hyqgWS1pjSMbmBObgl0SlIspqVDdtg/5LKIvVy7KLM2R36da9n6All8pL1dS2evG+d0m/xjCg6iKrK2uklkj3AAGbsc+YGato4zNg/OFDl54pFji1pTb0tVLCogANmdZ8Xf//fvdFQd91jorREEFI4EOZACPb/YBorcWMGNVk3VJRYy+vaIKfewYy0zzGAZ/tWsSh26dQNuGJ+SL01WQ== X-Forefront-PRVS: 01917B1794 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2479; 23:G309Q9dp2aUC8j6avgMQKtqUuqyQG5qn8hxwpOrdp?= =?us-ascii?Q?dExUM00lP9AEuVzMiFbDyfHMQffCyvfUc8/042AgLS36UNYvR9JaXdpabkzY?= =?us-ascii?Q?zxfVfWPsyv0VK6cekFEW44kjOCvIXS5PYp6jITuFGkO+Vyf/eotKydH2D6Va?= =?us-ascii?Q?LkvWe0eJQbyXPfX1UgvUQYRwqYj3L6fyPQX+Eka+RRRIBSZk7XAfA0yaH9g5?= =?us-ascii?Q?pTemtlLbK8lVM4WVODiIe1yCDZmMmsTldarvi9gjejNWb832y246K5FST8wl?= =?us-ascii?Q?UiPKBzDUrwArCkNrT30+HeqFVCgIgjgWHAGq0bISSn6FdIh2YGFw7x2kDXGU?= =?us-ascii?Q?0Zacjz9AieRvA/IWMVNweTr3XKa24tQx+zUjTC56O/ZS7ER1hboJd3VXMvtZ?= =?us-ascii?Q?Z3lmr+fBEAhzBYcSOts9ETYoOetvludSf5h6TD51aCjTfkml/3k/Z2MOGwlr?= =?us-ascii?Q?e0Bbupp+F7APn31yBVJFrwbYz//l/Aynz7/16QIgZSUqNwn8PQrGxv+Z9m6q?= =?us-ascii?Q?fIiG2QgnFh8TlaHWQbhvN2JKzDdWi5OckULUnT/IIxg/cEf+ctz+AY/6PXwg?= =?us-ascii?Q?ex2eIHCzZf5gI9Nute0G1C8AMiRY/HGwO5O8WxRPQUfSVjULck7SK7JXxWK2?= =?us-ascii?Q?xYD6KqDDZ5yJotxuxR7TtcxsJRvxmEgey4om9J4j6ZqrwlqpppLSqWuIKqfV?= =?us-ascii?Q?17mhZhWq1O0aVVUGLMM462k/cYtdHfxNbhicC3PhitAyLuHtJ8xNzoFaOri6?= =?us-ascii?Q?JUVwXqgwWaEUtYT/wk2Q7XCj0YehSIclfVjDRKVwblLhjwoPkuI7eG7SgxU/?= =?us-ascii?Q?0JPcW68rVdFWR22hkOXjdL4pxExtuoFEn4JoaJRkipv0OCvCvuFoRNmMDDd3?= =?us-ascii?Q?KoHeM23DzvMg0cdjuDFNaaEb9agR/Cx05cta+BVTREMsXNw22lcFBlMWywBd?= =?us-ascii?Q?3bjQV0fJtdmEjqJuZUBxXRnZEXX1d7OlTeMk53Yp1EfuotHzL3fe58UydHJE?= =?us-ascii?Q?rbGaE+O3CX4i7NXGe8iYcFxt/SzTxT+IWMe2729CAygjDGCpqEHWTCE9eGPJ?= =?us-ascii?Q?/Ec4kFqihdITGQjvX8lSkbNcqyy2H8OzoP6XugHTTeOZv3eugL0iK2x3mUp5?= =?us-ascii?Q?R5upY/LJvfViciBiFiXp3GmCnVaRvLiI36U1kNXa9fKR+JquqQMhjClWZvZH?= =?us-ascii?Q?iiqGviEZzR1LkVyqk8Fli9xvXRSMxzZDm62wND6b+nZ7yvO52gxfaW9UHzhq?= =?us-ascii?Q?846byZZ4yLfCqlQJMfJD8ZngQhWtnA2To5kh6l8bwcexIUhAINKMj42xfwAr?= =?us-ascii?Q?nwev4N7S7cwIJcwfAIl0bE1wiOgeU4MV4VtlZzJvFmm?= X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 6:3WKKop9py4n16iVGITRgV3xBzz16JHABW8B1sXuTOYT9SfFVSrTKDIIWHEqfC2+fqh81rEIxs5NqWi+PDsgI2XYVaJ6nnZeinqgIhQ381NYHgNGUuoV4xZcHPn8VGatPB4tW5JypjpZZiR35MeUOlXiy+EjZibGzCBeURX28VteBt2vmst1sp86pePfmAVObky+L6OsrzfKqGMAFyU+BvPQLec6/R9FFTNV3/U2BFmWw3YBq3DzMc1vMBPac3xFOzGZNNFc3D7m53XT9i56vyLI0dOBMy0pxNQyMDRhkYlMaLqpIqUayhcuJZa8niVeZfClTpg+L7p+4+n7IFi5iOaVkp+t9k74cQoCqGrO4Ma591tRcZCmrRZoCWtjdt6u+mkFKaK0uc00jp0vL5mveUAUSoqha1YfcroBvWGUeS/uCUKB54y84K8L0ztVFneJg; 5:2jeAYmHIZr1D2ftIudwFDOVrddxSu5SMvWONK3+Rz714U9/iy+m7JsrUOoJ67Ki8uUxyxKnCaqpv8mbGhgEBlNGxvH3o8KMsC7yZpa0NGHUNdbNfngcs+Ys+r0DG5zPRjc/OOYeKfuHWX+SYGekMzecndC+6BwbEoadWkIR8hERuWNf0ay9v2XGOLfcqrAaW; 24:uiPSUKSiuElERRxWnL4BBeXuR25QMXu8NylSDfjLsg3GHz9Z/TT8amJt++wbQ3hdtAL9c2GN1+qReexi6C65uUQmoBvrqjk6wpguDDT1PaE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2479; 7:yRP7LYpIg7PYw0S504RbcAKamXRknyjfklMF/dQltOozOhwY8G/SvadTSTAiWvbcdhsqJQoR9RWxO8HwH3iFJsXcMs8TpoF6ou9VgAPAIzYAh6JGkhkrPmjiE0HLQzU09IxPYoCwHF3bXxYZh7u2rZwbJpjviXWx7pZ6sJe6xswtik3b5fp3MwDU7SZRmtYRVEzn0j3tcP9SHZfVb41UCOH5PxMzDWi0DbH1ZuQWd9IULMZ8acT0yvPWK7WrdlSdcZiekBeD0d0LpLmDC0TMf/0JrX2BN74Cb/1GVh7hXez3pmwBc5UXAn6HVqbtLO+iHefBb/L8lciXSVD4+iSuaAvGPNDRv/g47sPCSKhWe+xFekj+gF/TkDUUkKBuGjyBfCEBB0AZg6jRc3MTbWKCR8eHSD0me97dkhx6VcY0THQ3pj9qrt4AUNK1bWYdscp338xnbiLJNCXg8GzqvdrzzQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2017 14:03:44.5719 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB2479 Subject: [dpdk-dev] [PATCH v10 08/13] eal/pci: add support for PCI bus X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jan 2017 14:03:47 -0000 Based on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch. EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices. Signed-off-by: Shreyansh Jain Reviewed-by: Ferruh Yigit --- lib/librte_eal/bsdapp/eal/eal.c | 1 + lib/librte_eal/bsdapp/eal/eal_pci.c | 11 ++++++ lib/librte_eal/common/eal_common_pci.c | 33 ++++++++++++++++ lib/librte_eal/common/include/rte_pci.h | 68 +++++++++++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_pci.c | 15 ++++++++ 5 files changed, 128 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index f0abd82..a584447 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 3a5c315..48bfe24 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -673,3 +673,14 @@ rte_eal_pci_init(void) } return 0; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), + .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus); diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 8b4ae2d..4cde957 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -479,3 +480,35 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver) rte_eal_driver_unregister(&driver->driver); TAILQ_REMOVE(&pci_driver_list, driver, next); } + +/* Add a PCI device to PCI Bus */ +void +rte_eal_pci_add_device(struct rte_pci_bus *pci_bus, + struct rte_pci_device *pci_dev) +{ + TAILQ_INSERT_TAIL(&pci_bus->device_list, pci_dev, next); + /* Update Bus references */ + pci_dev->device.bus = &pci_bus->bus; +} + +/* Insert a PCI device into a predefined position in PCI bus */ +void +rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev, + struct rte_pci_device *new_pci_dev) +{ + TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next); + /* Update Bus references */ + new_pci_dev->device.bus = exist_pci_dev->device.bus; +} + +/* Remove a PCI device from PCI bus */ +void +rte_eal_pci_remove_device(struct rte_pci_device *pci_dev) +{ + struct rte_pci_bus *pci_bus; + + pci_bus = container_of(pci_dev->device.bus, struct rte_pci_bus, bus); + TAILQ_REMOVE(&pci_bus->device_list, pci_dev, next); + /* Update Bus references */ + pci_dev->device.bus = NULL; +} diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index adc20b9..05cf693 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -85,6 +85,7 @@ extern "C" { #include #include #include +#include TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */ TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */ @@ -111,6 +112,25 @@ const char *pci_get_sysfs_path(void); /** Maximum number of PCI resources. */ #define PCI_MAX_RESOURCE 6 +/** Name of PCI Bus */ +#define PCI_BUS_NAME "PCI" + +/* Forward declarations */ +struct rte_pci_device; +struct rte_pci_driver; + +/** List of PCI devices */ +TAILQ_HEAD(rte_pci_device_list, rte_pci_device); +/** List of PCI drivers */ +TAILQ_HEAD(rte_pci_driver_list, rte_pci_driver); + +/* PCI Bus iterators */ +#define FOREACH_DEVICE_ON_PCIBUS(p) \ + TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next) + +#define FOREACH_DRIVER_ON_PCIBUS(p) \ + TAILQ_FOREACH(p, &(rte_pci_bus.driver_list), next) + /** * A structure describing an ID for a PCI driver. Each driver provides a * table of these IDs for each device that it supports. @@ -206,12 +226,22 @@ typedef int (pci_remove_t)(struct rte_pci_device *); struct rte_pci_driver { TAILQ_ENTRY(rte_pci_driver) next; /**< Next in list. */ struct rte_driver driver; /**< Inherit core driver. */ + struct rte_pci_bus *pci_bus; /**< PCI bus reference */ pci_probe_t *probe; /**< Device Probe function. */ pci_remove_t *remove; /**< Device Remove function. */ const struct rte_pci_id *id_table; /**< ID table, NULL terminated. */ uint32_t drv_flags; /**< Flags contolling handling of device. */ }; +/** + * Structure describing the PCI bus + */ +struct rte_pci_bus { + struct rte_bus bus; /**< Inherit the generic class */ + struct rte_pci_device_list device_list; /**< List of PCI devices */ + struct rte_pci_driver_list driver_list; /**< List of PCI drivers */ +}; + /** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */ #define RTE_PCI_DRV_NEED_MAPPING 0x0001 /** Device driver supports link state interrupt */ @@ -523,6 +553,44 @@ RTE_PMD_EXPORT_NAME(nm, __COUNTER__) void rte_eal_pci_unregister(struct rte_pci_driver *driver); /** + * Add a PCI device to the PCI Bus (append to PCI Device list). This function + * also updates the bus references of the PCI Device (and the generic device + * object embedded within. + * + * @param pci_bus + * PCI Bus reference to which device is to be added + * @param pci_dev + * PCI device to add + * @return void + */ +void rte_eal_pci_add_device(struct rte_pci_bus *pci_bus, + struct rte_pci_device *pci_dev); + +/** + * Insert a PCI device in the PCI Bus at a particular location in the device + * list. It also updates the PCI Bus reference of the new devices to be + * inserted. + * + * @param exist_pci_dev + * Existing PCI device in PCI Bus + * @param new_pci_dev + * PCI device to be added before exist_pci_dev + * @return void + */ +void rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev, + struct rte_pci_device *new_pci_dev); + +/** + * Remove a PCI device from the PCI Bus. This sets to NULL the bus references + * in the PCI device object as well as the generic device object. + * + * @param pci_device + * PCI device to be removed from PCI Bus + * @return void + */ +void rte_eal_pci_remove_device(struct rte_pci_device *pci_device); + +/** * Read PCI config space. * * @param device diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index e2fc219..300064d 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,9 @@ * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it). */ +/* Forward declaration of PCI bus */ +struct rte_pci_bus rte_pci_bus; + static int pci_get_kernel_driver_by_path(const char *filename, char *dri_name) { @@ -723,3 +727,14 @@ rte_eal_pci_init(void) return 0; } + +struct rte_pci_bus rte_pci_bus = { + .bus = { + .scan = rte_eal_pci_scan, + .probe = rte_eal_pci_probe, + }, + .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), + .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), +}; + +RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus); -- 2.7.4