hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
u-boot/cmd/pci.c
....@@ -47,7 +47,6 @@
4747 return pci_byte_size(size) * 2;
4848 }
4949
50
-#ifdef CONFIG_DM_PCI
5150 static void pci_show_regs(struct udevice *dev, struct pci_reg_info *regs)
5251 {
5352 for (; regs->name; regs++) {
....@@ -59,41 +58,8 @@
5958 pci_field_width(regs->size), val);
6059 }
6160 }
62
-#else
63
-static unsigned long pci_read_config(pci_dev_t dev, int offset,
64
- enum pci_size_t size)
65
-{
66
- u32 val32;
67
- u16 val16;
68
- u8 val8;
6961
70
- switch (size) {
71
- case PCI_SIZE_8:
72
- pci_read_config_byte(dev, offset, &val8);
73
- return val8;
74
- case PCI_SIZE_16:
75
- pci_read_config_word(dev, offset, &val16);
76
- return val16;
77
- case PCI_SIZE_32:
78
- default:
79
- pci_read_config_dword(dev, offset, &val32);
80
- return val32;
81
- }
82
-}
83
-
84
-static void pci_show_regs(pci_dev_t dev, struct pci_reg_info *regs)
85
-{
86
- for (; regs->name; regs++) {
87
- printf(" %s =%*s%#.*lx\n", regs->name,
88
- (int)(28 - strlen(regs->name)), "",
89
- pci_field_width(regs->size),
90
- pci_read_config(dev, regs->offset, regs->size));
91
- }
92
-}
93
-#endif
94
-
95
-#ifdef CONFIG_DM_PCI
96
-int pci_bar_show(struct udevice *dev)
62
+static int pci_bar_show(struct udevice *dev)
9763 {
9864 u8 header_type;
9965 int bar_cnt, bar_id, mem_type;
....@@ -105,9 +71,14 @@
10571 int prefetchable;
10672
10773 dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
74
+ header_type &= 0x7f;
10875
10976 if (header_type == PCI_HEADER_TYPE_CARDBUS) {
11077 printf("CardBus doesn't support BARs\n");
78
+ return -ENOSYS;
79
+ } else if (header_type != PCI_HEADER_TYPE_NORMAL &&
80
+ header_type != PCI_HEADER_TYPE_BRIDGE) {
81
+ printf("unknown header type\n");
11182 return -ENOSYS;
11283 }
11384
....@@ -149,7 +120,7 @@
149120
150121 if ((!is_64 && size_low) || (is_64 && size)) {
151122 size = ~size + 1;
152
- printf(" %d %#016llx %#016llx %d %s %s\n",
123
+ printf(" %d %#018llx %#018llx %d %s %s\n",
153124 bar_id, (unsigned long long)base,
154125 (unsigned long long)size, is_64 ? 64 : 32,
155126 is_io ? "I/O" : "MEM",
....@@ -162,7 +133,6 @@
162133
163134 return 0;
164135 }
165
-#endif
166136
167137 static struct pci_reg_info regs_start[] = {
168138 { "vendor ID", PCI_SIZE_16, PCI_VENDOR_ID },
....@@ -258,29 +228,18 @@
258228 *
259229 * @dev: Bus+Device+Function number
260230 */
261
-#ifdef CONFIG_DM_PCI
262
-void pci_header_show(struct udevice *dev)
263
-#else
264
-void pci_header_show(pci_dev_t dev)
265
-#endif
231
+static void pci_header_show(struct udevice *dev)
266232 {
267
-#ifdef CONFIG_DM_PCI
268233 unsigned long class, header_type;
269234
270235 dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8);
271236 dm_pci_read_config(dev, PCI_HEADER_TYPE, &header_type, PCI_SIZE_8);
272
-#else
273
- u8 class, header_type;
274
-
275
- pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
276
- pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
277
-#endif
278237 pci_show_regs(dev, regs_start);
279238 printf(" class code = 0x%.2x (%s)\n", (int)class,
280239 pci_class_str(class));
281240 pci_show_regs(dev, regs_rest);
282241
283
- switch (header_type & 0x03) {
242
+ switch (header_type & 0x7f) {
284243 case PCI_HEADER_TYPE_NORMAL: /* "normal" PCI device */
285244 pci_show_regs(dev, regs_normal);
286245 break;
....@@ -297,17 +256,14 @@
297256 }
298257 }
299258
300
-void pciinfo_header(int busnum, bool short_listing)
259
+static void pciinfo_header(bool short_listing)
301260 {
302
- printf("Scanning PCI devices on bus %d\n", busnum);
303
-
304261 if (short_listing) {
305262 printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n");
306263 printf("_____________________________________________________________\n");
307264 }
308265 }
309266
310
-#ifdef CONFIG_DM_PCI
311267 /**
312268 * pci_header_show_brief() - Show the short-form PCI device header
313269 *
....@@ -330,11 +286,15 @@
330286 pci_class_str(class), subclass);
331287 }
332288
333
-static void pciinfo(struct udevice *bus, bool short_listing)
289
+static void pciinfo(struct udevice *bus, bool short_listing, bool multi)
334290 {
335291 struct udevice *dev;
336292
337
- pciinfo_header(bus->seq, short_listing);
293
+ if (!multi)
294
+ printf("Scanning PCI devices on bus %d\n", bus->seq);
295
+
296
+ if (!multi || bus->seq == 0)
297
+ pciinfo_header(short_listing);
338298
339299 for (device_find_first_child(bus, &dev);
340300 dev;
....@@ -353,102 +313,6 @@
353313 }
354314 }
355315 }
356
-
357
-#else
358
-
359
-/**
360
- * pci_header_show_brief() - Show the short-form PCI device header
361
- *
362
- * Reads and prints the header of the specified PCI device in short form.
363
- *
364
- * @dev: Bus+Device+Function number
365
- */
366
-void pci_header_show_brief(pci_dev_t dev)
367
-{
368
- u16 vendor, device;
369
- u8 class, subclass;
370
-
371
- pci_read_config_word(dev, PCI_VENDOR_ID, &vendor);
372
- pci_read_config_word(dev, PCI_DEVICE_ID, &device);
373
- pci_read_config_byte(dev, PCI_CLASS_CODE, &class);
374
- pci_read_config_byte(dev, PCI_CLASS_SUB_CODE, &subclass);
375
-
376
- printf("0x%.4x 0x%.4x %-23s 0x%.2x\n",
377
- vendor, device,
378
- pci_class_str(class), subclass);
379
-}
380
-
381
-/**
382
- * pciinfo() - Show a list of devices on the PCI bus
383
- *
384
- * Show information about devices on PCI bus. Depending on @short_pci_listing
385
- * the output will be more or less exhaustive.
386
- *
387
- * @bus_num: The number of the bus to be scanned
388
- * @short_pci_listing: true to use short form, showing only a brief header
389
- * for each device
390
- */
391
-void pciinfo(int bus_num, int short_pci_listing)
392
-{
393
- struct pci_controller *hose = pci_bus_to_hose(bus_num);
394
- int device;
395
- int function;
396
- unsigned char header_type;
397
- unsigned short vendor_id;
398
- pci_dev_t dev;
399
- int ret;
400
-
401
- if (!hose)
402
- return;
403
-
404
- pciinfo_header(bus_num, short_pci_listing);
405
-
406
- for (device = 0; device < PCI_MAX_PCI_DEVICES; device++) {
407
- header_type = 0;
408
- vendor_id = 0;
409
- for (function = 0; function < PCI_MAX_PCI_FUNCTIONS;
410
- function++) {
411
- /*
412
- * If this is not a multi-function device, we skip
413
- * the rest.
414
- */
415
- if (function && !(header_type & 0x80))
416
- break;
417
-
418
- dev = PCI_BDF(bus_num, device, function);
419
-
420
- if (pci_skip_dev(hose, dev))
421
- continue;
422
-
423
- ret = pci_read_config_word(dev, PCI_VENDOR_ID,
424
- &vendor_id);
425
- if (ret)
426
- goto error;
427
- if ((vendor_id == 0xFFFF) || (vendor_id == 0x0000))
428
- continue;
429
-
430
- if (!function) {
431
- pci_read_config_byte(dev, PCI_HEADER_TYPE,
432
- &header_type);
433
- }
434
-
435
- if (short_pci_listing) {
436
- printf("%02x.%02x.%02x ", bus_num, device,
437
- function);
438
- pci_header_show_brief(dev);
439
- } else {
440
- printf("\nFound PCI device %02x.%02x.%02x:\n",
441
- bus_num, device, function);
442
- pci_header_show(dev);
443
- }
444
- }
445
- }
446
-
447
- return;
448
-error:
449
- printf("Cannot read bus configuration: %d\n", ret);
450
-}
451
-#endif
452316
453317 /**
454318 * get_pci_dev() - Convert the "bus.device.function" identifier into a number
....@@ -481,13 +345,8 @@
481345 return PCI_BDF(bdfs[0], bdfs[1], bdfs[2]);
482346 }
483347
484
-#ifdef CONFIG_DM_PCI
485348 static int pci_cfg_display(struct udevice *dev, ulong addr,
486349 enum pci_size_t size, ulong length)
487
-#else
488
-static int pci_cfg_display(pci_dev_t bdf, ulong addr, enum pci_size_t size,
489
- ulong length)
490
-#endif
491350 {
492351 #define DISP_LINE_LEN 16
493352 ulong i, nbytes, linebytes;
....@@ -508,11 +367,7 @@
508367 for (i = 0; i < linebytes; i += byte_size) {
509368 unsigned long val;
510369
511
-#ifdef CONFIG_DM_PCI
512370 dm_pci_read_config(dev, addr, &val, size);
513
-#else
514
- val = pci_read_config(bdf, addr, size);
515
-#endif
516371 printf(" %0*lx", pci_field_width(size), val);
517372 addr += byte_size;
518373 }
....@@ -527,31 +382,8 @@
527382 return (rc);
528383 }
529384
530
-#ifndef CONFIG_DM_PCI
531
-static int pci_cfg_write (pci_dev_t bdf, ulong addr, ulong size, ulong value)
532
-{
533
- if (size == 4) {
534
- pci_write_config_dword(bdf, addr, value);
535
- }
536
- else if (size == 2) {
537
- ushort val = value & 0xffff;
538
- pci_write_config_word(bdf, addr, val);
539
- }
540
- else {
541
- u_char val = value & 0xff;
542
- pci_write_config_byte(bdf, addr, val);
543
- }
544
- return 0;
545
-}
546
-#endif
547
-
548
-#ifdef CONFIG_DM_PCI
549385 static int pci_cfg_modify(struct udevice *dev, ulong addr, ulong size,
550386 ulong value, int incrflag)
551
-#else
552
-static int pci_cfg_modify(pci_dev_t bdf, ulong addr, ulong size, ulong value,
553
- int incrflag)
554
-#endif
555387 {
556388 ulong i;
557389 int nbytes;
....@@ -562,11 +394,7 @@
562394 */
563395 do {
564396 printf("%08lx:", addr);
565
-#ifdef CONFIG_DM_PCI
566397 dm_pci_read_config(dev, addr, &val, size);
567
-#else
568
- val = pci_read_config(bdf, addr, size);
569
-#endif
570398 printf(" %0*lx", pci_field_width(size), val);
571399
572400 nbytes = cli_readline(" ? ");
....@@ -593,11 +421,7 @@
593421 /* good enough to not time out
594422 */
595423 bootretry_reset_cmd_timeout();
596
-#ifdef CONFIG_DM_PCI
597424 dm_pci_write_config(dev, addr, i, size);
598
-#else
599
- pci_cfg_write(bdf, addr, size, i);
600
-#endif
601425 if (incrflag)
602426 addr += size;
603427 }
....@@ -607,7 +431,6 @@
607431 return 0;
608432 }
609433
610
-#ifdef CONFIG_DM_PCI
611434 static const struct pci_flag_info {
612435 uint flag;
613436 const char *name;
....@@ -621,7 +444,7 @@
621444
622445 static void pci_show_regions(struct udevice *bus)
623446 {
624
- struct pci_controller *hose = dev_get_uclass_priv(bus);
447
+ struct pci_controller *hose = dev_get_uclass_priv(pci_get_controller(bus));
625448 const struct pci_region *reg;
626449 int i, j;
627450
....@@ -630,10 +453,11 @@
630453 return;
631454 }
632455
633
- printf("# %-16s %-16s %-16s %s\n", "Bus start", "Phys start", "Size",
456
+ printf("Buses %02x-%02x\n", hose->first_busno, hose->last_busno);
457
+ printf("# %-18s %-18s %-18s %s\n", "Bus start", "Phys start", "Size",
634458 "Flags");
635459 for (i = 0, reg = hose->regions; i < hose->region_count; i++, reg++) {
636
- printf("%d %#016llx %#016llx %#016llx ", i,
460
+ printf("%d %#018llx %#018llx %#018llx ", i,
637461 (unsigned long long)reg->bus_start,
638462 (unsigned long long)reg->phys_start,
639463 (unsigned long long)reg->size);
....@@ -646,7 +470,6 @@
646470 printf("\n");
647471 }
648472 }
649
-#endif
650473
651474 /* PCI Configuration Space access commands
652475 *
....@@ -660,15 +483,12 @@
660483 {
661484 ulong addr = 0, value = 0, cmd_size = 0;
662485 enum pci_size_t size = PCI_SIZE_32;
663
-#ifdef CONFIG_DM_PCI
664486 struct udevice *dev, *bus;
665
-#else
666
- pci_dev_t dev;
667
-#endif
668
- int busnum = 0;
487
+ int busnum = -1;
669488 pci_dev_t bdf = 0;
670489 char cmd = 's';
671490 int ret = 0;
491
+ char *endp;
672492
673493 if (argc > 1)
674494 cmd = argv[1][0];
....@@ -686,19 +506,15 @@
686506 if (argc > 4)
687507 value = simple_strtoul(argv[4], NULL, 16);
688508 case 'h': /* header */
689
-#ifdef CONFIG_DM_PCI
690509 case 'b': /* bars */
691
-#endif
692510 if (argc < 3)
693511 goto usage;
694512 if ((bdf = get_pci_dev(argv[2])) == -1)
695513 return 1;
696514 break;
697
-#if defined(CONFIG_DM_PCI)
698515 case 'e':
699516 pci_init();
700517 return 0;
701
-#endif
702518 case 'r': /* no break */
703519 default: /* scan bus */
704520 value = 1; /* short listing */
....@@ -707,10 +523,37 @@
707523 value = 0;
708524 argc--;
709525 }
710
- if (argc > 1)
711
- busnum = simple_strtoul(argv[1], NULL, 16);
526
+ if (argc > 2 || (argc > 1 && cmd != 'r' && argv[1][0] != 's')) {
527
+ if (argv[argc - 1][0] != '*') {
528
+ busnum = simple_strtoul(argv[argc - 1], &endp, 16);
529
+ if (*endp)
530
+ goto usage;
531
+ }
532
+ argc--;
533
+ }
534
+ if (cmd == 'r' && argc > 2)
535
+ goto usage;
536
+ else if (cmd != 'r' && (argc > 2 || (argc == 2 && argv[1][0] != 's')))
537
+ goto usage;
712538 }
713
-#ifdef CONFIG_DM_PCI
539
+ if (busnum == -1) {
540
+ if (cmd != 'r') {
541
+ for (busnum = 0;
542
+ uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0;
543
+ busnum++)
544
+ pciinfo(bus, value, true);
545
+ } else {
546
+ for (busnum = 0;
547
+ uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0;
548
+ busnum++) {
549
+ /* Regions are controller specific so skip non-root buses */
550
+ if (device_is_on_pci_bus(bus))
551
+ continue;
552
+ pci_show_regions(bus);
553
+ }
554
+ }
555
+ return 0;
556
+ }
714557 ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus);
715558 if (ret) {
716559 printf("No such bus\n");
....@@ -719,22 +562,15 @@
719562 if (cmd == 'r')
720563 pci_show_regions(bus);
721564 else
722
- pciinfo(bus, value);
723
-#else
724
- pciinfo(busnum, value);
725
-#endif
565
+ pciinfo(bus, value, false);
726566 return 0;
727567 }
728568
729
-#ifdef CONFIG_DM_PCI
730569 ret = dm_pci_bus_find_bdf(bdf, &dev);
731570 if (ret) {
732571 printf("No such device\n");
733572 return CMD_RET_FAILURE;
734573 }
735
-#else
736
- dev = bdf;
737
-#endif
738574
739575 switch (argv[1][0]) {
740576 case 'h': /* header */
....@@ -755,17 +591,10 @@
755591 case 'w': /* write */
756592 if (argc < 5)
757593 goto usage;
758
-#ifdef CONFIG_DM_PCI
759594 ret = dm_pci_write_config(dev, addr, value, size);
760
-#else
761
- ret = pci_cfg_write(dev, addr, size, value);
762
-#endif
763595 break;
764
-#ifdef CONFIG_DM_PCI
765
-
766596 case 'b': /* bars */
767597 return pci_bar_show(dev);
768
-#endif
769598 default:
770599 ret = CMD_RET_USAGE;
771600 break;
....@@ -780,20 +609,16 @@
780609
781610 #ifdef CONFIG_SYS_LONGHELP
782611 static char pci_help_text[] =
783
- "[bus] [long]\n"
612
+ "[bus|*] [long]\n"
784613 " - short or long list of PCI devices on bus 'bus'\n"
785
-#if defined(CONFIG_DM_PCI)
786614 "pci enum\n"
787615 " - Enumerate PCI buses\n"
788
-#endif
789616 "pci header b.d.f\n"
790617 " - show header of PCI device 'bus.device.function'\n"
791
-#ifdef CONFIG_DM_PCI
792618 "pci bar b.d.f\n"
793619 " - show BARs base and size for device b.d.f'\n"
794
- "pci regions\n"
620
+ "pci regions [bus|*]\n"
795621 " - show PCI regions\n"
796
-#endif
797622 "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n"
798623 " - display PCI configuration space (CFG)\n"
799624 "pci next[.b, .w, .l] b.d.f address\n"