bus/fslmc: introduce fsl-mc bus driver
[dpdk.git] / drivers / bus / fslmc / fslmc_bus.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2016 NXP. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of NXP nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <string.h>
34 #include <dirent.h>
35
36 #include <rte_log.h>
37 #include <rte_bus.h>
38 #include <rte_eal_memconfig.h>
39 #include <rte_malloc.h>
40 #include <rte_devargs.h>
41 #include <rte_memcpy.h>
42 #include <rte_ethdev.h>
43
44 #include "rte_fslmc.h"
45
46 #define FSLMC_BUS_LOG(level, fmt, args...) \
47         RTE_LOG(level, EAL, "%s(): " fmt "\n", __func__, ##args)
48
49 struct rte_fslmc_bus rte_fslmc_bus;
50
51 static int
52 rte_fslmc_scan(void)
53 {
54         return 0;
55 }
56
57 static int
58 rte_fslmc_match(struct rte_dpaa2_driver *dpaa2_drv,
59                 struct rte_dpaa2_device *dpaa2_dev)
60 {
61         if (dpaa2_drv->drv_type == dpaa2_dev->dev_type)
62                 return 0;
63
64         return 1;
65 }
66
67 static int
68 rte_fslmc_probe(void)
69 {
70         int ret = 0;
71         struct rte_dpaa2_device *dev;
72         struct rte_dpaa2_driver *drv;
73
74         TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
75                 TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
76                         ret = rte_fslmc_match(drv, dev);
77                         if (ret)
78                                 continue;
79
80                         if (!drv->probe)
81                                 continue;
82
83                         ret = drv->probe(drv, dev);
84                         if (ret)
85                                 FSLMC_BUS_LOG(ERR, "Unable to probe.\n");
86                         break;
87                 }
88         }
89         return ret;
90 }
91
92 /*register a fslmc bus based dpaa2 driver */
93 void
94 rte_fslmc_driver_register(struct rte_dpaa2_driver *driver)
95 {
96         RTE_VERIFY(driver);
97
98         TAILQ_INSERT_TAIL(&rte_fslmc_bus.driver_list, driver, next);
99         /* Update Bus references */
100         driver->fslmc_bus = &rte_fslmc_bus;
101 }
102
103 /*un-register a fslmc bus based dpaa2 driver */
104 void
105 rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver)
106 {
107         struct rte_fslmc_bus *fslmc_bus;
108
109         fslmc_bus = driver->fslmc_bus;
110
111         TAILQ_REMOVE(&fslmc_bus->driver_list, driver, next);
112         /* Update Bus references */
113         driver->fslmc_bus = NULL;
114 }
115
116 struct rte_fslmc_bus rte_fslmc_bus = {
117         .bus = {
118                 .scan = rte_fslmc_scan,
119                 .probe = rte_fslmc_probe,
120         },
121         .device_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.device_list),
122         .driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
123 };
124
125 RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);