Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(C) 2023 Marvell. 3 : : */ 4 : : 5 : : #include <string.h> 6 : : #include <errno.h> 7 : : 8 : : #include <rte_bus.h> 9 : : #include <rte_common.h> 10 : : #include <rte_dev.h> 11 : : #include <rte_errno.h> 12 : : #include <rte_kvargs.h> 13 : : #include <rte_vfio.h> 14 : : 15 : : #include "bus_platform_driver.h" 16 : : #include "private.h" 17 : : 18 : : #ifdef VFIO_PRESENT 19 : : 20 : : enum platform_params { 21 : : RTE_PLATFORM_PARAM_NAME, 22 : : }; 23 : : 24 : : static const char * const platform_params_keys[] = { 25 : : [RTE_PLATFORM_PARAM_NAME] = "name", 26 : : NULL 27 : : }; 28 : : 29 : : static int 30 : 0 : platform_dev_match(const struct rte_device *dev, const void *_kvlist) 31 : : { 32 : : const char *key = platform_params_keys[RTE_PLATFORM_PARAM_NAME]; 33 : : const struct rte_kvargs *kvlist = _kvlist; 34 : : const char *name; 35 : : 36 : : /* no kvlist arg, all devices match */ 37 [ # # ]: 0 : if (kvlist == NULL) 38 : : return 0; 39 : : 40 : : /* if key is present in kvlist and does not match, filter device */ 41 : 0 : name = rte_kvargs_get(kvlist, key); 42 [ # # # # ]: 0 : if (name != NULL && strcmp(name, dev->name)) 43 : 0 : return -1; 44 : : 45 : : return 0; 46 : : } 47 : : 48 : : void * 49 : 0 : platform_bus_dev_iterate(const void *start, const char *str, 50 : : const struct rte_dev_iterator *it __rte_unused) 51 : : { 52 : : rte_bus_find_device_t find_device; 53 : : struct rte_kvargs *kvargs = NULL; 54 : : struct rte_device *dev; 55 : : 56 [ # # ]: 0 : if (str != NULL) { 57 : 0 : kvargs = rte_kvargs_parse(str, platform_params_keys); 58 [ # # ]: 0 : if (!kvargs) { 59 : 0 : PLATFORM_LOG(ERR, "cannot parse argument list %s", str); 60 : 0 : rte_errno = EINVAL; 61 : 0 : return NULL; 62 : : } 63 : : } 64 : : 65 : 0 : find_device = platform_bus.bus.find_device; 66 [ # # ]: 0 : if (find_device == NULL) { 67 : 0 : rte_kvargs_free(kvargs); 68 : 0 : return NULL; 69 : : } 70 : : 71 : 0 : dev = platform_bus.bus.find_device(start, platform_dev_match, kvargs); 72 : 0 : rte_kvargs_free(kvargs); 73 : : 74 : 0 : return dev; 75 : : } 76 : : 77 : : #endif /* VFIO_PRESENT */