1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2021 Oxide Computer Company 14 */ 15 16 #ifndef _PCIEADM_H 17 #define _PCIEADM_H 18 19 /* 20 * Common definitions for pcieadm(8). 21 */ 22 23 #include <libdevinfo.h> 24 #include <pcidb.h> 25 #include <priv.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 typedef struct pcieadm pcieadm_t; 32 33 typedef struct pcieadm_cmdtab { 34 const char *pct_name; 35 int (*pct_func)(pcieadm_t *, int, char **); 36 void (*pct_use)(FILE *); 37 } pcieadm_cmdtab_t; 38 39 struct pcieadm { 40 uint_t pia_indent; 41 di_node_t pia_root; 42 const char *pia_devstr; 43 di_node_t pia_devi; 44 di_node_t pia_nexus; 45 pcidb_hdl_t *pia_pcidb; 46 const pcieadm_cmdtab_t *pia_cmdtab; 47 priv_set_t *pia_priv_init; 48 priv_set_t *pia_priv_min; 49 priv_set_t *pia_priv_eff; 50 }; 51 52 typedef struct { 53 void *pdw_arg; 54 int (*pdw_func)(di_node_t, void *); 55 } pcieadm_di_walk_t; 56 57 /* 58 * Config space related 59 */ 60 typedef boolean_t (*pcieadm_cfgspace_f)(uint32_t, uint8_t, void *, void *); 61 62 /* 63 * Utilities 64 */ 65 extern void pcieadm_di_walk(pcieadm_t *, pcieadm_di_walk_t *); 66 extern void pcieadm_init_cfgspace_kernel(pcieadm_t *, pcieadm_cfgspace_f *, 67 void **); 68 extern void pcieadm_fini_cfgspace_kernel(void *); 69 extern void pcieadm_init_cfgspace_file(pcieadm_t *, const char *, 70 pcieadm_cfgspace_f *, void **); 71 extern void pcieadm_fini_cfgspace_file(void *); 72 extern void pcieadm_find_nexus(pcieadm_t *); 73 extern void pcieadm_find_dip(pcieadm_t *, const char *); 74 75 /* 76 * Output related 77 */ 78 extern const char *pcieadm_progname; 79 extern void pcieadm_indent(void); 80 extern void pcieadm_deindent(void); 81 extern void pcieadm_print(const char *, ...); 82 extern void pcieadm_ofmt_errx(const char *, ...); 83 84 /* 85 * Command tabs 86 */ 87 extern int pcieadm_save_cfgspace(pcieadm_t *, int, char *[]); 88 extern void pcieadm_save_cfgspace_usage(FILE *); 89 extern int pcieadm_show_cfgspace(pcieadm_t *, int, char *[]); 90 extern void pcieadm_show_cfgspace_usage(FILE *); 91 extern int pcieadm_show_devs(pcieadm_t *, int, char *[]); 92 extern void pcieadm_show_devs_usage(FILE *); 93 94 #define EXIT_USAGE 2 95 96 /* 97 * Privilege related. Note there are no centralized functions around raising and 98 * lowering privs as that unfortunately makes ROPs more easy to execute. 99 */ 100 extern void pcieadm_init_privs(pcieadm_t *); 101 102 /* 103 * XXX Maybe not here: 104 */ 105 #define BITX(u, h, l) (((u) >> (l)) & ((1LU << ((h) - (l) + 1LU)) - 1LU)) 106 107 #ifdef __cplusplus 108 } 109 #endif 110 111 #endif /* _PCIEADM_H */ 112