diff mbox series

[API-NEXT,PATCHv2,12/23] linux-gen: drv: driver: adding device querry function

Message ID 1490194110-40168-13-git-send-email-christophe.milard@linaro.org
State New
Headers show
Series driver items registration and probing | expand

Commit Message

Christophe Milard March 22, 2017, 2:48 p.m. UTC
Implementation of the device query function for the linux-gen ODP.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 platform/linux-generic/drv_driver.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

-- 
2.7.4
diff mbox series

Patch

diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c
index 60edde1..3e4780b 100644
--- a/platform/linux-generic/drv_driver.c
+++ b/platform/linux-generic/drv_driver.c
@@ -391,6 +391,43 @@  static void device_destroy_terminate(odpdrv_device_t drv_device)
 	_odp_ishm_pool_free(list_elt_pool, device);
 }
 
+odpdrv_device_t *odpdrv_device_query(odpdrv_enumr_t enumr, const char *address)
+{
+	_odpdrv_device_t *dev;
+	odpdrv_device_t *res;
+	int index = 0;
+
+	int size = sizeof(odpdrv_device_t); /* for the ODPDRV_DEVICE_INVALID */
+
+	/* parse the list of device a first time to determine the size of
+	 * the memory to be allocated:
+	 */
+	dev_list_read_lock();
+	dev = device_lst.head;
+	while (dev) {
+		if ((dev->param.enumerator == enumr) &&
+		    ((address == NULL) ||
+		     (strcmp(dev->param.address, address) == 0)))
+			size += sizeof(odpdrv_device_t);
+		dev = dev->next;
+	}
+
+	/* then fill the list: */
+	res = (odpdrv_device_t *)malloc(size);
+	dev = device_lst.head;
+	while (dev) {
+		if ((dev->param.enumerator == enumr) &&
+		    ((address == NULL) ||
+		     (strcmp(dev->param.address, address) == 0)))
+			res[index++] = (odpdrv_device_t)dev;
+		dev = dev->next;
+	}
+	dev_list_read_unlock();
+	res[index++] = ODPDRV_DEVICE_INVALID;
+
+	return res; /* must be freed by caller! */
+}
+
 odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param)
 {
 	ODP_ERR("NOT Supported yet! Driver %s Registration!\n.",