1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <stdio.h>
26 
27 static char *pcitool_usage_text[] = {
28 "Usage:",
29 "Probe mode:",
30 " %s [ <PCI nexus node> ] [ -a ] [ -p ] [ -v ] [ -q ]",
31 "",
32 " %s <PCI nexus node> [ -p [ bus=<bus>,dev=<dev>,func=<func> ] [ -v ] [ -q ]",
33 " %s <PCI nexus node> [ -p [ bdf=<bus>.<dev>.<func> ] [ -v ] [-q ]",
34 "",
35 "Register peek/poke mode:",
36 " %s <PCI nexus node>",
37 "  [   -n bank=<register bank>",
38 "         where register bank is 0 for mapped jbus space and 1 for pcie space",
39 "         (only on applicable platforms)",
40 "",
41 "      -n base=<base address>",
42 "         where base address is a physical base address of a register bank",
43 "         (only on applicable platforms (e.g. sun4v) where bank info is "
44 	"unavailable)",
45 "",
46 "      -d bus=<bus>,dev=<dev>,func=<func>,bank=<register bank>",
47 "      -d bdf=<bus>.<dev>.<func>,bank=<register bank>",
48 "",
49 "      -d bus=<bus>,dev=<dev>,func=<func> | bdf=<bus>.<dev>.<func> ,",
50 "	  [ config | bar0 | bar1 | bar2 | bar3 | bar4 | bar5 | rom ]",
51 "	  (spaces added for clarity but are not allowed in the command)",
52 "",
53 "  -n and -d options may also include:",
54 "",
55 "  [ -w <value to write> ] [ -r ]",
56 "  [ -o <offset> ]",
57 "  [ -s 1 | 2 | 4 | 8 ]",
58 "  [ -e b | l ]",
59 "  [ -l ]",
60 "  [ -b <number bytes to dump> [ -c ] [ -x ] ]",
61 "  [ -v ]",
62 "  [ -q ]",
63 "",
64 "  -n may also include:",
65 "",
66 "  [ -y ]",
67 "",
68 "Interrupt mode:",
69 " X86:",
70 " %s pci@<unit-address> -i <cpu#,ino#> | all",
71 "       [ -r [ -c ] |  -w <cpu#> [ -g ] ] [ -v ] [ -q ]",
72 " SPARC:",
73 " %s pci@<unit-address> -i <ino#> | all",
74 "       [ -r [ -c ] |  -w <cpu#> [ -g ] ] [ -v ] [ -q ]",
75 " %s pci@<unit-address> -m <msi#> | all",
76 "       [ -r [ -c ] |  -w <cpu#> [ -g ] ] [ -v ] [ -q ]",
77 "",
78 "where",
79 "",
80 "pci@<unit-address> is a node from /devices, with \"/devices\" stripped off.",
81 "For example: /pci@0,0",
82 "",
83 "-v gives verbose output for all modes.",
84 "",
85 "-q suppresses error output (except for commandline parsing errors) for all "
86 	"modes",
87 "   (Note that errno status is returned to the shell upon termination.)",
88 "",
89 "Online help mode:",
90 " %s -h",
91 "   Prints this message.",
92 "",
93 "Probe mode",
94 "----------",
95 "",
96 "-p [ bus=<bus>,dev=<dev>,func=<func> | bdf=<bus>.<dev>.<func> ]",
97 "     Specify bus, device and/or function of devices to search for and dump.",
98 "",
99 "-a Probe all buses.  By default, pcitool checks the PCI nexus node's",
100 "bus-range property to restrict which buses are probed.  This option",
101 "cannot be combined with an explicit bus specification.",
102 "",
103 "If a PCI nexus node is specified, pcitool looks only for devices",
104 "under that node.  If no PCI nexus node is specified, pcitool looks",
105 "for devices under all PCI nexus nodes.  PCI nexus nodes, which can",
106 "be used for other pcitool commands, are printed at the top of each tree.",
107 "",
108 "Non-verbose probe mode prints config register data as follows:",
109 "  aa bb c dddd eeee ffff gggg hh iiiiii jj kk ll mm",
110 "  where...",
111 "    a = pci bus number",
112 "    b = pci device number",
113 "    c = pci function number",
114 "    d = vendor ID",
115 "    e = device ID",
116 "    f = command register",
117 "    g = status register",
118 "    h = revision ID",
119 "    i = class code",
120 "    j = cache line size",
121 "    k = latency timer",
122 "    l = header type",
123 "    m = built in self test register (bist)",
124 "",
125 "Register peek/poke mode",
126 "-----------------------",
127 "",
128 "-n requests nexus node info.",
129 "   Specify desired nexus register using -o <register offset>",
130 "",
131 "-d requests device (leaf) node info.",
132 "   Specify bus, dev, function bits (from probe mode) as hex numbers.",
133 "   Bank is specified in one of the following ways:",
134 "     By value: 0 == config space, 1 == BAR0, 2 == BAR1, ..., 6 == BAR5, "
135 	"7 == ROM",
136 "     By BAR (bus addr reg): config, bar0, bar1, bar2, bar3, bar4, bar5, rom",
137 "",
138 "Above peek/poke mode selections take the following options:",
139 "",
140 "-r for reading (default)",
141 "-w <value> for writing",
142 "-w <value> -r for writing a value followed by a readback",
143 "",
144 "-o <offset> to specify an offset within the requested address space",
145 "",
146 "-s <size specifier>: 1, 2, 4 or 8 bytes, default 4",
147 "   (8-byte transfers on supported platforms only)",
148 "",
149 "-e <endian specifier>: b or l (ell), default is l for little endian>",
150 "",
151 "-l to do repetitious accesses to/from the same location(s)",
152 "",
153 "-b <number of bytes to dump> [ -c ] to get a formatted multiple register dump",
154 "   starting at the offset given.  Hex bytes are always dumped.",
155 "   -c dumps characters as well.  "
156 	"Non-printable characters are dumped as \"@\".",
157 "   -x keeps going on errors, and prints err characters as X",
158 "",
159 "Above nexus peek/poke mode selections take the following additional option:",
160 "",
161 "-y to confirm a base_addr without being prompted interactively",
162 "",
163 "NOTE: Some platforms (i.e. SPARC) return peek/poke errors as failed ioctls;",
164 "    Other platforms (i.e. X86) return peek/poke errors as FF values.",
165 "",
166 "All numeric values are in HEX",
167 "",
168 "Interrupt mode",
169 "--------------",
170 "",
171 "-i <[cpu#],ino#> changes or retrieves current interrupts information of given",
172 "   nexus and given INO. The special value of 'all' can be used to select all",
173 "   INOs.",
174 "",
175 "-m <[cpu#],msi#> changes or retrieves current interrupts information of given",
176 "   nexus and given MSI/X. The special value of 'all' can be used to select",
177 "   all MSI/Xs.",
178 "",
179 "   Note: [cpu#] is available on x86 platform, is to identify exclusive vector",
180 "   with ino# at the same time. [cpu#] is not supported on SPARC platform.",
181 "",
182 "   Note: On x86 platforms, both INOs and MSI/Xs are mapped to the same",
183 "   interrupt vectors. Use -i option to retrieve and reroute any interrupt",
184 "   vectors (both INO and MSI/Xs).  So, -m option is not required on x86",
185 "   platforms. Hence it is not supported.",
186 "",
187 "   A specific INO or MSI/X must be selected if -w specified.",
188 "",
189 "-w <cpu#> [ -g ] to change an INO or MSI/X <->CPU binding.",
190 "",
191 "   Note: On certain platforms (e.g. X86), multiple MSI interrupts of a single",
192 "   function need to be moved together.  Use -g to do this.  -g works only on",
193 "   supported platforms and only for groups of MSI interrupts.  When -g is",
194 "   used, INO must be the lowest-numbered vector of the group.  (Use the mdb",
195 "   ::interrupts dcmd to discover groups of MSI vectors.)  The size of the",
196 "   group is determined internally.  (\"Groups\" of size 1 are accepted.)",
197 "",
198 "-r [ -c ] for displaying ino or msi <->CPU bindings of all selected INO/MSIs",
199 "   on a given nexus.  -c optionally dumps controller information.",
200 "",
201 "   All relevant enabled INO/MSI/Xs supporting non-nexus device interrupts",
202 "   will be printed.  For each printed INO/MSI/X, all supported devices and",
203 "   their CPU binding will be displayed.  On some platforms, INOs dedicated",
204 "   to the root nexus will be shown and marked with \"(Internal)\".",
205 "",
206 "When neither -r nor -w are specified, -r is the default.",
207 NULL
208 };
209 
210 
211 /*
212  * Print usage statement.
213  *
214  * Text is too large for many print statements.
215  *
216  * Instead, loop through the array of strings in pcitool_usage_text.
217  * Print program name when %s is in the text.
218  */
219 void
usage(char * name)220 usage(char *name)
221 {
222 	int i;
223 
224 	for (i = 0; pcitool_usage_text[i] != NULL; i++) {
225 		(void) printf(pcitool_usage_text[i], name);
226 		(void) printf("\n");
227 	}
228 }
229