2019-10-25 17:34:18 +00:00
|
|
|
// Copyright 2019, Collabora, Ltd.
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Just does a probe.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-05-26 21:47:07 +00:00
|
|
|
#include "xrt/xrt_instance.h"
|
|
|
|
#include "xrt/xrt_device.h"
|
2019-10-25 17:34:18 +00:00
|
|
|
#include "cli_common.h"
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2020-05-26 21:47:07 +00:00
|
|
|
do_exit(struct xrt_instance **xi_ptr, int ret)
|
2019-10-25 17:34:18 +00:00
|
|
|
{
|
2020-05-26 21:47:07 +00:00
|
|
|
xrt_instance_destroy(xi_ptr);
|
2019-10-25 17:34:18 +00:00
|
|
|
|
|
|
|
printf(" :: Exiting '%i'\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NUM_XDEVS 32
|
|
|
|
|
|
|
|
int
|
|
|
|
cli_cmd_probe(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
struct xrt_device *xdevs[NUM_XDEVS] = {0};
|
2020-05-26 21:47:07 +00:00
|
|
|
struct xrt_instance *xi = NULL;
|
2019-10-25 17:34:18 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
// Initialize the prober.
|
2020-05-26 21:47:07 +00:00
|
|
|
printf(" :: Creating instance!\n");
|
2019-10-25 17:34:18 +00:00
|
|
|
|
2020-06-17 06:36:38 +00:00
|
|
|
ret = xrt_instance_create(&xi, NULL);
|
2019-10-25 17:34:18 +00:00
|
|
|
if (ret != 0) {
|
2020-05-26 21:47:07 +00:00
|
|
|
return do_exit(&xi, 0);
|
2019-10-25 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Need to prime the prober with devices before dumping and listing.
|
2020-05-26 21:47:07 +00:00
|
|
|
printf(" :: Probing and selecting!\n");
|
2019-10-25 17:34:18 +00:00
|
|
|
|
2020-05-26 21:47:07 +00:00
|
|
|
ret = xrt_instance_select(xi, xdevs, NUM_XDEVS);
|
2019-10-25 17:34:18 +00:00
|
|
|
if (ret != 0) {
|
2020-05-26 21:47:07 +00:00
|
|
|
return do_exit(&xi, ret);
|
2019-10-25 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// End of program
|
|
|
|
printf(" :: All ok, shutting down.\n");
|
|
|
|
|
|
|
|
for (size_t i = 0; i < NUM_XDEVS; i++) {
|
|
|
|
if (xdevs[i] == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\tDestroying '%s'\n", xdevs[i]->str);
|
2020-05-26 21:47:07 +00:00
|
|
|
xrt_device_destroy(&xdevs[i]);
|
2019-10-25 17:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally done
|
2020-05-26 21:47:07 +00:00
|
|
|
return do_exit(&xi, 0);
|
2019-10-25 17:34:18 +00:00
|
|
|
}
|