Blame tools/fpgainfo/portinfo.c

Packit 534379
// Copyright(c) 2018-2020, Intel Corporation
Packit 534379
//
Packit 534379
// Redistribution  and  use  in source  and  binary  forms,  with  or  without
Packit 534379
// modification, are permitted provided that the following conditions are met:
Packit 534379
//
Packit 534379
// * Redistributions of  source code  must retain the  above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer.
Packit 534379
// * Redistributions in binary form must reproduce the above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer in the documentation
Packit 534379
//   and/or other materials provided with the distribution.
Packit 534379
// * Neither the name  of Intel Corporation  nor the names of its contributors
Packit 534379
//   may be used to  endorse or promote  products derived  from this  software
Packit 534379
//   without specific prior written permission.
Packit 534379
//
Packit 534379
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 534379
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO,  THE
Packit 534379
// IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 534379
// ARE DISCLAIMED.  IN NO EVENT  SHALL THE COPYRIGHT OWNER  OR CONTRIBUTORS BE
Packit 534379
// LIABLE  FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
Packit 534379
// CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT  OF
Packit 534379
// SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
Packit 534379
// INTERRUPTION)  HOWEVER CAUSED  AND ON ANY THEORY  OF LIABILITY,  WHETHER IN
Packit 534379
// CONTRACT,  STRICT LIABILITY,  OR TORT  (INCLUDING NEGLIGENCE  OR OTHERWISE)
Packit 534379
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
Packit 534379
// POSSIBILITY OF SUCH DAMAGE.
Packit 534379
Packit 534379
#include <getopt.h>
Packit 534379
#include "fpgainfo.h"
Packit 534379
#include "portinfo.h"
Packit 534379
#include <opae/fpga.h>
Packit 534379
#include <uuid/uuid.h>
Packit 534379
Packit 534379
/*
Packit 534379
 * Print help
Packit 534379
 */
Packit 534379
void port_help(void)
Packit 534379
{
Packit 534379
	printf("\nPrint accelerator port information\n"
Packit 534379
	       "        fpgainfo port [-h]\n"
Packit 534379
	       "                -h,--help           Print this help\n"
Packit 534379
	       "\n");
Packit 534379
}
Packit 534379
Packit 534379
static void print_port_info(fpga_token token)
Packit 534379
{
Packit 534379
	char guid_str[38];
Packit 534379
	fpga_guid guid;
Packit 534379
	fpga_properties props;
Packit 534379
	fpga_result res = FPGA_OK;
Packit 534379
	res = fpgaGetProperties(token, &props;;
Packit 534379
	ON_FPGAINFO_ERR_GOTO(res, out_destroy,
Packit 534379
			     "Failure reading properties from token");
Packit 534379
	fpgainfo_print_common("//****** PORT ******//", props);
Packit 534379
Packit 534379
	res = fpgaPropertiesGetGUID(props, &guid);
Packit 534379
	ON_FPGAINFO_ERR_GOTO(res, out_destroy,
Packit 534379
			     "reading guid from properties");
Packit 534379
	uuid_unparse(guid, guid_str);
Packit 534379
	printf("%-32s : %s\n", "Accelerator GUID", guid_str);
Packit 534379
Packit 534379
out_destroy:
Packit 534379
	res = fpgaDestroyProperties(&props;;
Packit 534379
	ON_FPGAINFO_ERR_GOTO(res, out_exit,
Packit 534379
			     "destroying properties");
Packit 534379
Packit 534379
out_exit:
Packit 534379
	return;
Packit 534379
}
Packit 534379
Packit 534379
fpga_result port_filter(fpga_properties *filter, int argc, char *argv[])
Packit 534379
{
Packit 534379
	(void)argc;
Packit 534379
	(void)argv;
Packit 534379
	fpga_result res = FPGA_OK;
Packit 534379
	res = fpgaPropertiesSetObjectType(*filter, FPGA_ACCELERATOR);
Packit 534379
	fpgainfo_print_err("setting type to FPGA_ACCELERATOR", res);
Packit 534379
	return res;
Packit 534379
}
Packit 534379
Packit 534379
fpga_result port_command(fpga_token *tokens, int num_tokens, int argc,
Packit 534379
			 char *argv[])
Packit 534379
{
Packit 534379
	(void)argc;
Packit 534379
	(void)argv;
Packit 534379
Packit 534379
	fpga_result res = FPGA_OK;
Packit 534379
Packit 534379
	optind = 0;
Packit 534379
	struct option longopts[] = {
Packit 534379
		{"help", no_argument, NULL, 'h'},
Packit 534379
		{0, 0, 0, 0},
Packit 534379
	};
Packit 534379
Packit 534379
	int getopt_ret;
Packit 534379
	int option_index;
Packit 534379
Packit 534379
	while (-1
Packit 534379
	       != (getopt_ret = getopt_long(argc, argv, ":h", longopts,
Packit 534379
					    &option_index))) {
Packit 534379
		const char *tmp_optarg = optarg;
Packit 534379
Packit 534379
		if ((optarg) && ('=' == *tmp_optarg)) {
Packit 534379
			++tmp_optarg;
Packit 534379
		}
Packit 534379
Packit 534379
		switch (getopt_ret) {
Packit 534379
		case 'h': /* help */
Packit 534379
			port_help();
Packit 534379
			return res;
Packit 534379
Packit 534379
		case ':': /* missing option argument */
Packit 534379
			OPAE_ERR("Missing option argument\n");
Packit 534379
			port_help();
Packit 534379
			return FPGA_INVALID_PARAM;
Packit 534379
Packit 534379
		case '?':
Packit 534379
		default: /* invalid option */
Packit 534379
			OPAE_ERR("Invalid cmdline options\n");
Packit 534379
			port_help();
Packit 534379
			return FPGA_INVALID_PARAM;
Packit 534379
		}
Packit 534379
	}
Packit 534379
Packit 534379
	int i = 0;
Packit 534379
	for (i = 0; i < num_tokens; ++i) {
Packit 534379
		print_port_info(tokens[i]);
Packit 534379
	}
Packit 534379
Packit 534379
	return res;
Packit 534379
}