blob: c0765fd7fb49b143c816ceeda1b656430460f6c8 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
3 * Andreas Heppel <aheppel@sysgo.de>
4 *
5 * (C) Copyright 2002
6 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +000010 */
11
12/*
13 * PCI routines
14 */
15
16#include <common.h>
Simon Glass0098e172014-04-10 20:01:30 -060017#include <bootretry.h>
Simon Glass18d66532014-04-10 20:01:25 -060018#include <cli.h>
wdenkc6097192002-11-03 00:24:07 +000019#include <command.h>
Simon Glass24b852a2015-11-08 23:47:45 -070020#include <console.h>
wdenkc6097192002-11-03 00:24:07 +000021#include <asm/processor.h>
22#include <asm/io.h>
wdenkc6097192002-11-03 00:24:07 +000023#include <pci.h>
24
Simon Glass07a58872015-11-26 19:51:20 -070025struct pci_reg_info {
26 const char *name;
27 enum pci_size_t size;
28 u8 offset;
29};
30
31static int pci_field_width(enum pci_size_t size)
32{
33 switch (size) {
34 case PCI_SIZE_8:
35 return 2;
36 case PCI_SIZE_16:
37 return 4;
38 case PCI_SIZE_32:
39 default:
40 return 8;
41 }
42}
43
44static unsigned long pci_read_config(pci_dev_t dev, int offset,
45 enum pci_size_t size)
46{
47 u32 val32;
48 u16 val16;
49 u8 val8;
50
51 switch (size) {
52 case PCI_SIZE_8:
53 pci_read_config_byte(dev, offset, &val8);
54 return val8;
55 case PCI_SIZE_16:
56 pci_read_config_word(dev, offset, &val16);
57 return val16;
58 case PCI_SIZE_32:
59 default:
60 pci_read_config_dword(dev, offset, &val32);
61 return val32;
62 }
63}
64
65static void pci_show_regs(pci_dev_t dev, struct pci_reg_info *regs)
66{
67 for (; regs->name; regs++) {
68 printf(" %s =%*s%#.*lx\n", regs->name,
69 (int)(28 - strlen(regs->name)), "",
70 pci_field_width(regs->size),
71 pci_read_config(dev, regs->offset, regs->size));
72 }
73}
74
75static struct pci_reg_info regs_start[] = {
76 { "vendor ID", PCI_SIZE_16, PCI_VENDOR_ID },
77 { "device ID", PCI_SIZE_16, PCI_DEVICE_ID },
78 { "command register ID", PCI_SIZE_16, PCI_COMMAND },
79 { "status register", PCI_SIZE_16, PCI_STATUS },
80 { "revision ID", PCI_SIZE_8, PCI_REVISION_ID },
81 {},
82};
83
84static struct pci_reg_info regs_rest[] = {
85 { "sub class code", PCI_SIZE_8, PCI_CLASS_SUB_CODE },
86 { "programming interface", PCI_SIZE_8, PCI_CLASS_PROG },
87 { "cache line", PCI_SIZE_8, PCI_CACHE_LINE_SIZE },
88 { "latency time", PCI_SIZE_8, PCI_LATENCY_TIMER },
89 { "header type", PCI_SIZE_8, PCI_HEADER_TYPE },
90 { "BIST", PCI_SIZE_8, PCI_BIST },
91 { "base address 0", PCI_SIZE_32, PCI_BASE_ADDRESS_0 },
92 {},
93};
94
95static struct pci_reg_info regs_normal[] = {
96 { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
97 { "base address 2", PCI_SIZE_32, PCI_BASE_ADDRESS_2 },
98 { "base address 3", PCI_SIZE_32, PCI_BASE_ADDRESS_3 },
99 { "base address 4", PCI_SIZE_32, PCI_BASE_ADDRESS_4 },
100 { "base address 5", PCI_SIZE_32, PCI_BASE_ADDRESS_5 },
101 { "cardBus CIS pointer", PCI_SIZE_32, PCI_CARDBUS_CIS },
102 { "sub system vendor ID", PCI_SIZE_16, PCI_SUBSYSTEM_VENDOR_ID },
103 { "sub system ID", PCI_SIZE_16, PCI_SUBSYSTEM_ID },
104 { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS },
105 { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
106 { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
107 { "min Grant", PCI_SIZE_8, PCI_MIN_GNT },
108 { "max Latency", PCI_SIZE_8, PCI_MAX_LAT },
109 {},
110};
111
112static struct pci_reg_info regs_bridge[] = {
113 { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
114 { "primary bus number", PCI_SIZE_8, PCI_PRIMARY_BUS },
115 { "secondary bus number", PCI_SIZE_8, PCI_SECONDARY_BUS },
116 { "subordinate bus number", PCI_SIZE_8, PCI_SUBORDINATE_BUS },
117 { "secondary latency timer", PCI_SIZE_8, PCI_SEC_LATENCY_TIMER },
118 { "IO base", PCI_SIZE_8, PCI_IO_BASE },
119 { "IO limit", PCI_SIZE_8, PCI_IO_LIMIT },
120 { "secondary status", PCI_SIZE_16, PCI_SEC_STATUS },
121 { "memory base", PCI_SIZE_16, PCI_MEMORY_BASE },
122 { "memory limit", PCI_SIZE_16, PCI_MEMORY_LIMIT },
123 { "prefetch memory base", PCI_SIZE_16, PCI_PREF_MEMORY_BASE },
124 { "prefetch memory limit", PCI_SIZE_16, PCI_PREF_MEMORY_LIMIT },
125 { "prefetch memory base upper", PCI_SIZE_32, PCI_PREF_BASE_UPPER32 },
126 { "prefetch memory limit upper", PCI_SIZE_32, PCI_PREF_LIMIT_UPPER32 },
127 { "IO base upper 16 bits", PCI_SIZE_16, PCI_IO_BASE_UPPER16 },
128 { "IO limit upper 16 bits", PCI_SIZE_16, PCI_IO_LIMIT_UPPER16 },
129 { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS1 },
130 { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
131 { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
132 { "bridge control", PCI_SIZE_16, PCI_BRIDGE_CONTROL },
133 {},
134};
135
136static struct pci_reg_info regs_cardbus[] = {
137 { "capabilities", PCI_SIZE_8, PCI_CB_CAPABILITY_LIST },
138 { "secondary status", PCI_SIZE_16, PCI_CB_SEC_STATUS },
139 { "primary bus number", PCI_SIZE_8, PCI_CB_PRIMARY_BUS },
140 { "CardBus number", PCI_SIZE_8, PCI_CB_CARD_BUS },
141 { "subordinate bus number", PCI_SIZE_8, PCI_CB_SUBORDINATE_BUS },
142 { "CardBus latency timer", PCI_SIZE_8, PCI_CB_LATENCY_TIMER },
143 { "CardBus memory base 0", PCI_SIZE_32, PCI_CB_MEMORY_BASE_0 },
144 { "CardBus memory limit 0", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_0 },
145 { "CardBus memory base 1", PCI_SIZE_32, PCI_CB_MEMORY_BASE_1 },
146 { "CardBus memory limit 1", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_1 },
147 { "CardBus IO base 0", PCI_SIZE_16, PCI_CB_IO_BASE_0 },
148 { "CardBus IO base high 0", PCI_SIZE_16, PCI_CB_IO_BASE_0_HI },
149 { "CardBus IO limit 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0 },
150 { "CardBus IO limit high 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0_HI },
151 { "CardBus IO base 1", PCI_SIZE_16, PCI_CB_IO_BASE_1 },
152 { "CardBus IO base high 1", PCI_SIZE_16, PCI_CB_IO_BASE_1_HI },
153 { "CardBus IO limit 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1 },
154 { "CardBus IO limit high 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1_HI },
155 { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
156 { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
157 { "bridge control", PCI_SIZE_16, PCI_CB_BRIDGE_CONTROL },
158 { "subvendor ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_VENDOR_ID },
159 { "subdevice ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_ID },
160 { "PC Card 16bit base address", PCI_SIZE_32, PCI_CB_LEGACY_MODE_BASE },
161 {},
162};
163
Simon Glassc2be0702015-11-26 19:51:25 -0700164/**
165 * pci_header_show() - Show the header of the specified PCI device.
wdenkc6097192002-11-03 00:24:07 +0000166 *
Simon Glassc2be0702015-11-26 19:51:25 -0700167 * @dev: Bus+Device+Function number
wdenkc6097192002-11-03 00:24:07 +0000168 */
169void pci_header_show(pci_dev_t dev)
170{
Simon Glass07a58872015-11-26 19:51:20 -0700171 u8 class, header_type;
wdenkc6097192002-11-03 00:24:07 +0000172
Simon Glass49f835f2015-11-26 19:51:24 -0700173 pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
wdenkc6097192002-11-03 00:24:07 +0000174 pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
Simon Glass07a58872015-11-26 19:51:20 -0700175 pci_show_regs(dev, regs_start);
wdenkc6097192002-11-03 00:24:07 +0000176
Simon Glass07a58872015-11-26 19:51:20 -0700177 printf(" class code = 0x%.2x (%s)\n", class,
178 pci_class_str(class));
179 pci_show_regs(dev, regs_rest);
wdenkc6097192002-11-03 00:24:07 +0000180
wdenk7c7a23b2002-12-07 00:20:59 +0000181 switch (header_type & 0x03) {
182 case PCI_HEADER_TYPE_NORMAL: /* "normal" PCI device */
Simon Glass07a58872015-11-26 19:51:20 -0700183 pci_show_regs(dev, regs_normal);
wdenk7c7a23b2002-12-07 00:20:59 +0000184 break;
wdenk7c7a23b2002-12-07 00:20:59 +0000185 case PCI_HEADER_TYPE_BRIDGE: /* PCI-to-PCI bridge */
Simon Glass07a58872015-11-26 19:51:20 -0700186 pci_show_regs(dev, regs_bridge);
wdenk7c7a23b2002-12-07 00:20:59 +0000187 break;
wdenk7c7a23b2002-12-07 00:20:59 +0000188 case PCI_HEADER_TYPE_CARDBUS: /* PCI-to-CardBus bridge */
Simon Glass07a58872015-11-26 19:51:20 -0700189 pci_show_regs(dev, regs_cardbus);
wdenk7c7a23b2002-12-07 00:20:59 +0000190 break;
wdenk8bde7f72003-06-27 21:31:46 +0000191
wdenk7c7a23b2002-12-07 00:20:59 +0000192 default:
193 printf("unknown header\n");
wdenk8bde7f72003-06-27 21:31:46 +0000194 break;
wdenkc6097192002-11-03 00:24:07 +0000195 }
wdenkc6097192002-11-03 00:24:07 +0000196}
197
Simon Glassc2be0702015-11-26 19:51:25 -0700198/**
199 * pci_header_show_brief() - Show the short-form PCI device header
Simon Glass49f835f2015-11-26 19:51:24 -0700200 *
Simon Glassc2be0702015-11-26 19:51:25 -0700201 * Reads and prints the header of the specified PCI device in short form.
Simon Glass49f835f2015-11-26 19:51:24 -0700202 *
Simon Glassc2be0702015-11-26 19:51:25 -0700203 * @dev: Bus+Device+Function number
Simon Glass49f835f2015-11-26 19:51:24 -0700204 */
205void pci_header_show_brief(pci_dev_t dev)
206{
207 u16 vendor, device;
208 u8 class, subclass;
209
210 pci_read_config_word(dev, PCI_VENDOR_ID, &vendor);
211 pci_read_config_word(dev, PCI_DEVICE_ID, &device);
212 pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
213 pci_read_config_byte(dev, PCI_CLASS_SUB_CODE, &subclass);
214
215 printf("0x%.4x 0x%.4x %-23s 0x%.2x\n",
216 vendor, device,
217 pci_class_str(class), subclass);
218}
219
Simon Glassc2be0702015-11-26 19:51:25 -0700220/**
221 * pciinfo() - Show a list of devices on the PCI bus
Simon Glass49f835f2015-11-26 19:51:24 -0700222 *
Simon Glassc2be0702015-11-26 19:51:25 -0700223 * Show information about devices on PCI bus. Depending on @short_pci_listing
224 * the output will be more or less exhaustive.
Simon Glass49f835f2015-11-26 19:51:24 -0700225 *
Simon Glassc2be0702015-11-26 19:51:25 -0700226 * @bus_num: The number of the bus to be scanned
227 * @short_pci_listing: true to use short form, showing only a brief header
228 * for each device
Simon Glass49f835f2015-11-26 19:51:24 -0700229 */
230void pciinfo(int bus_num, int short_pci_listing)
231{
232 struct pci_controller *hose = pci_bus_to_hose(bus_num);
Simon Glassc2be0702015-11-26 19:51:25 -0700233 int device;
234 int function;
235 unsigned char header_type;
236 unsigned short vendor_id;
Simon Glass49f835f2015-11-26 19:51:24 -0700237 pci_dev_t dev;
238 int ret;
239
240 if (!hose)
241 return;
242
243 printf("Scanning PCI devices on bus %d\n", bus_num);
244
245 if (short_pci_listing) {
246 printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n");
247 printf("_____________________________________________________________\n");
248 }
249
Simon Glassc2be0702015-11-26 19:51:25 -0700250 for (device = 0; device < PCI_MAX_PCI_DEVICES; device++) {
251 header_type = 0;
252 vendor_id = 0;
253 for (function = 0; function < PCI_MAX_PCI_FUNCTIONS;
254 function++) {
Simon Glass49f835f2015-11-26 19:51:24 -0700255 /*
256 * If this is not a multi-function device, we skip
257 * the rest.
258 */
Simon Glassc2be0702015-11-26 19:51:25 -0700259 if (function && !(header_type & 0x80))
Simon Glass49f835f2015-11-26 19:51:24 -0700260 break;
261
Simon Glassc2be0702015-11-26 19:51:25 -0700262 dev = PCI_BDF(bus_num, device, function);
Simon Glass49f835f2015-11-26 19:51:24 -0700263
264 if (pci_skip_dev(hose, dev))
265 continue;
266
267 ret = pci_read_config_word(dev, PCI_VENDOR_ID,
Simon Glassc2be0702015-11-26 19:51:25 -0700268 &vendor_id);
Simon Glass49f835f2015-11-26 19:51:24 -0700269 if (ret)
270 goto error;
Simon Glassc2be0702015-11-26 19:51:25 -0700271 if ((vendor_id == 0xFFFF) || (vendor_id == 0x0000))
Simon Glass49f835f2015-11-26 19:51:24 -0700272 continue;
273
Simon Glassc2be0702015-11-26 19:51:25 -0700274 if (!function) {
Simon Glass49f835f2015-11-26 19:51:24 -0700275 pci_read_config_byte(dev, PCI_HEADER_TYPE,
Simon Glassc2be0702015-11-26 19:51:25 -0700276 &header_type);
Simon Glass49f835f2015-11-26 19:51:24 -0700277 }
278
279 if (short_pci_listing) {
Simon Glassc2be0702015-11-26 19:51:25 -0700280 printf("%02x.%02x.%02x ", bus_num, device,
281 function);
Simon Glass49f835f2015-11-26 19:51:24 -0700282 pci_header_show_brief(dev);
283 } else {
284 printf("\nFound PCI device %02x.%02x.%02x:\n",
Simon Glassc2be0702015-11-26 19:51:25 -0700285 bus_num, device, function);
Simon Glass49f835f2015-11-26 19:51:24 -0700286 pci_header_show(dev);
287 }
288 }
289 }
290
291 return;
292error:
293 printf("Cannot read bus configuration: %d\n", ret);
294}
295
296
Simon Glassc2be0702015-11-26 19:51:25 -0700297/**
298 * get_pci_dev() - Convert the "bus.device.function" identifier into a number
299 *
300 * @name: Device string in the form "bus.device.function" where each is in hex
301 * @return encoded pci_dev_t or -1 if the string was invalid
wdenkc6097192002-11-03 00:24:07 +0000302 */
Simon Glassc2be0702015-11-26 19:51:25 -0700303static pci_dev_t get_pci_dev(char *name)
wdenkc6097192002-11-03 00:24:07 +0000304{
305 char cnum[12];
306 int len, i, iold, n;
307 int bdfs[3] = {0,0,0};
308
309 len = strlen(name);
310 if (len > 8)
311 return -1;
312 for (i = 0, iold = 0, n = 0; i < len; i++) {
313 if (name[i] == '.') {
314 memcpy(cnum, &name[iold], i - iold);
315 cnum[i - iold] = '\0';
316 bdfs[n++] = simple_strtoul(cnum, NULL, 16);
317 iold = i + 1;
318 }
319 }
320 strcpy(cnum, &name[iold]);
321 if (n == 0)
322 n = 1;
323 bdfs[n] = simple_strtoul(cnum, NULL, 16);
Simon Glassc2be0702015-11-26 19:51:25 -0700324
wdenkc6097192002-11-03 00:24:07 +0000325 return PCI_BDF(bdfs[0], bdfs[1], bdfs[2]);
326}
327
328static int pci_cfg_display(pci_dev_t bdf, ulong addr, ulong size, ulong length)
329{
330#define DISP_LINE_LEN 16
331 ulong i, nbytes, linebytes;
332 int rc = 0;
333
334 if (length == 0)
335 length = 0x40 / size; /* Standard PCI configuration space */
336
337 /* Print the lines.
338 * once, and all accesses are with the specified bus width.
339 */
340 nbytes = length * size;
341 do {
342 uint val4;
343 ushort val2;
344 u_char val1;
345
346 printf("%08lx:", addr);
347 linebytes = (nbytes>DISP_LINE_LEN)?DISP_LINE_LEN:nbytes;
348 for (i=0; i<linebytes; i+= size) {
349 if (size == 4) {
350 pci_read_config_dword(bdf, addr, &val4);
351 printf(" %08x", val4);
352 } else if (size == 2) {
353 pci_read_config_word(bdf, addr, &val2);
354 printf(" %04x", val2);
355 } else {
356 pci_read_config_byte(bdf, addr, &val1);
357 printf(" %02x", val1);
358 }
359 addr += size;
360 }
361 printf("\n");
362 nbytes -= linebytes;
363 if (ctrlc()) {
364 rc = 1;
365 break;
366 }
367 } while (nbytes > 0);
368
369 return (rc);
370}
371
372static int pci_cfg_write (pci_dev_t bdf, ulong addr, ulong size, ulong value)
373{
374 if (size == 4) {
375 pci_write_config_dword(bdf, addr, value);
376 }
377 else if (size == 2) {
378 ushort val = value & 0xffff;
379 pci_write_config_word(bdf, addr, val);
380 }
381 else {
382 u_char val = value & 0xff;
383 pci_write_config_byte(bdf, addr, val);
384 }
385 return 0;
386}
387
388static int
389pci_cfg_modify (pci_dev_t bdf, ulong addr, ulong size, ulong value, int incrflag)
390{
391 ulong i;
392 int nbytes;
wdenkc6097192002-11-03 00:24:07 +0000393 uint val4;
394 ushort val2;
395 u_char val1;
396
397 /* Print the address, followed by value. Then accept input for
398 * the next value. A non-converted value exits.
399 */
400 do {
401 printf("%08lx:", addr);
402 if (size == 4) {
403 pci_read_config_dword(bdf, addr, &val4);
404 printf(" %08x", val4);
405 }
406 else if (size == 2) {
407 pci_read_config_word(bdf, addr, &val2);
408 printf(" %04x", val2);
409 }
410 else {
411 pci_read_config_byte(bdf, addr, &val1);
412 printf(" %02x", val1);
413 }
414
Simon Glasse1bf8242014-04-10 20:01:27 -0600415 nbytes = cli_readline(" ? ");
wdenkc6097192002-11-03 00:24:07 +0000416 if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
417 /* <CR> pressed as only input, don't modify current
418 * location and move to next. "-" pressed will go back.
419 */
420 if (incrflag)
421 addr += nbytes ? -size : size;
422 nbytes = 1;
Simon Glassb26440f2014-04-10 20:01:31 -0600423 /* good enough to not time out */
424 bootretry_reset_cmd_timeout();
wdenkc6097192002-11-03 00:24:07 +0000425 }
426#ifdef CONFIG_BOOT_RETRY_TIME
427 else if (nbytes == -2) {
428 break; /* timed out, exit the command */
429 }
430#endif
431 else {
432 char *endp;
433 i = simple_strtoul(console_buffer, &endp, 16);
434 nbytes = endp - console_buffer;
435 if (nbytes) {
wdenkc6097192002-11-03 00:24:07 +0000436 /* good enough to not time out
437 */
Simon Glassb26440f2014-04-10 20:01:31 -0600438 bootretry_reset_cmd_timeout();
wdenkc6097192002-11-03 00:24:07 +0000439 pci_cfg_write (bdf, addr, size, i);
440 if (incrflag)
441 addr += size;
442 }
443 }
444 } while (nbytes);
445
446 return 0;
447}
448
449/* PCI Configuration Space access commands
450 *
451 * Syntax:
452 * pci display[.b, .w, .l] bus.device.function} [addr] [len]
453 * pci next[.b, .w, .l] bus.device.function [addr]
454 * pci modify[.b, .w, .l] bus.device.function [addr]
455 * pci write[.b, .w, .l] bus.device.function addr value
456 */
Kim Phillips088f1b12012-10-29 13:34:31 +0000457static int do_pci(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc6097192002-11-03 00:24:07 +0000458{
459 ulong addr = 0, value = 0, size = 0;
Simon Glassca7de762015-11-26 19:51:19 -0700460 int busnum = 0;
wdenkc6097192002-11-03 00:24:07 +0000461 pci_dev_t bdf = 0;
462 char cmd = 's';
Simon Glassbfa41912015-11-26 19:51:18 -0700463 int ret = 0;
wdenkc6097192002-11-03 00:24:07 +0000464
465 if (argc > 1)
466 cmd = argv[1][0];
467
468 switch (cmd) {
469 case 'd': /* display */
470 case 'n': /* next */
471 case 'm': /* modify */
472 case 'w': /* write */
473 /* Check for a size specification. */
474 size = cmd_get_data_size(argv[1], 4);
475 if (argc > 3)
476 addr = simple_strtoul(argv[3], NULL, 16);
477 if (argc > 4)
478 value = simple_strtoul(argv[4], NULL, 16);
479 case 'h': /* header */
480 if (argc < 3)
481 goto usage;
482 if ((bdf = get_pci_dev(argv[2])) == -1)
483 return 1;
484 break;
John Schmoller96d61602010-10-22 00:20:23 -0500485#ifdef CONFIG_CMD_PCI_ENUM
486 case 'e':
487 break;
488#endif
wdenkc6097192002-11-03 00:24:07 +0000489 default: /* scan bus */
490 value = 1; /* short listing */
wdenkc6097192002-11-03 00:24:07 +0000491 if (argc > 1) {
492 if (argv[argc-1][0] == 'l') {
493 value = 0;
494 argc--;
495 }
496 if (argc > 1)
Simon Glassca7de762015-11-26 19:51:19 -0700497 busnum = simple_strtoul(argv[1], NULL, 16);
wdenkc6097192002-11-03 00:24:07 +0000498 }
Simon Glassca7de762015-11-26 19:51:19 -0700499 pciinfo(busnum, value);
wdenkc6097192002-11-03 00:24:07 +0000500 return 0;
501 }
502
503 switch (argv[1][0]) {
504 case 'h': /* header */
505 pci_header_show(bdf);
Simon Glassbfa41912015-11-26 19:51:18 -0700506 break;
wdenkc6097192002-11-03 00:24:07 +0000507 case 'd': /* display */
508 return pci_cfg_display(bdf, addr, size, value);
John Schmoller96d61602010-10-22 00:20:23 -0500509#ifdef CONFIG_CMD_PCI_ENUM
510 case 'e':
Simon Glass871bc922015-11-19 20:26:56 -0700511# ifdef CONFIG_DM_PCI
512 printf("This command is not yet supported with driver model\n");
513# else
John Schmoller96d61602010-10-22 00:20:23 -0500514 pci_init();
Simon Glass871bc922015-11-19 20:26:56 -0700515# endif
Simon Glassbfa41912015-11-26 19:51:18 -0700516 break;
John Schmoller96d61602010-10-22 00:20:23 -0500517#endif
wdenkc6097192002-11-03 00:24:07 +0000518 case 'n': /* next */
519 if (argc < 4)
520 goto usage;
Simon Glassbfa41912015-11-26 19:51:18 -0700521 ret = pci_cfg_modify(bdf, addr, size, value, 0);
522 break;
wdenkc6097192002-11-03 00:24:07 +0000523 case 'm': /* modify */
524 if (argc < 4)
525 goto usage;
Simon Glassbfa41912015-11-26 19:51:18 -0700526 ret = pci_cfg_modify(bdf, addr, size, value, 1);
527 break;
wdenkc6097192002-11-03 00:24:07 +0000528 case 'w': /* write */
529 if (argc < 5)
530 goto usage;
Simon Glassbfa41912015-11-26 19:51:18 -0700531 ret = pci_cfg_write(bdf, addr, size, value);
532 break;
533 default:
534 ret = CMD_RET_USAGE;
535 break;
wdenkc6097192002-11-03 00:24:07 +0000536 }
537
Simon Glassbfa41912015-11-26 19:51:18 -0700538 return ret;
wdenkc6097192002-11-03 00:24:07 +0000539 usage:
Simon Glass4c12eeb2011-12-10 08:44:01 +0000540 return CMD_RET_USAGE;
wdenkc6097192002-11-03 00:24:07 +0000541}
542
wdenk8bde7f72003-06-27 21:31:46 +0000543/***************************************************/
544
Kim Phillips088f1b12012-10-29 13:34:31 +0000545#ifdef CONFIG_SYS_LONGHELP
546static char pci_help_text[] =
wdenk8bde7f72003-06-27 21:31:46 +0000547 "[bus] [long]\n"
548 " - short or long list of PCI devices on bus 'bus'\n"
John Schmoller96d61602010-10-22 00:20:23 -0500549#ifdef CONFIG_CMD_PCI_ENUM
550 "pci enum\n"
551 " - re-enumerate PCI buses\n"
552#endif
wdenk8bde7f72003-06-27 21:31:46 +0000553 "pci header b.d.f\n"
554 " - show header of PCI device 'bus.device.function'\n"
555 "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n"
556 " - display PCI configuration space (CFG)\n"
557 "pci next[.b, .w, .l] b.d.f address\n"
558 " - modify, read and keep CFG address\n"
559 "pci modify[.b, .w, .l] b.d.f address\n"
560 " - modify, auto increment CFG address\n"
561 "pci write[.b, .w, .l] b.d.f address value\n"
Kim Phillips088f1b12012-10-29 13:34:31 +0000562 " - write to CFG address";
563#endif
564
565U_BOOT_CMD(
566 pci, 5, 1, do_pci,
567 "list and access PCI Configuration Space", pci_help_text
wdenk8bde7f72003-06-27 21:31:46 +0000568);