2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2002-11-03 00:24:07 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Andreas Heppel <aheppel@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
* Wolfgang Grandegger, DENX Software Engineering, wg@denx.de.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCI routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2014-04-11 02:01:30 +00:00
|
|
|
#include <bootretry.h>
|
2014-04-11 02:01:25 +00:00
|
|
|
#include <cli.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <command.h>
|
2015-11-09 06:47:45 +00:00
|
|
|
#include <console.h>
|
2015-11-27 02:51:29 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <pci.h>
|
|
|
|
|
2015-11-27 02:51:20 +00:00
|
|
|
struct pci_reg_info {
|
|
|
|
const char *name;
|
|
|
|
enum pci_size_t size;
|
|
|
|
u8 offset;
|
|
|
|
};
|
|
|
|
|
2015-11-27 02:51:26 +00:00
|
|
|
static int pci_byte_size(enum pci_size_t size)
|
2015-11-27 02:51:20 +00:00
|
|
|
{
|
|
|
|
switch (size) {
|
|
|
|
case PCI_SIZE_8:
|
2015-11-27 02:51:26 +00:00
|
|
|
return 1;
|
2015-11-27 02:51:20 +00:00
|
|
|
case PCI_SIZE_16:
|
2015-11-27 02:51:26 +00:00
|
|
|
return 2;
|
2015-11-27 02:51:20 +00:00
|
|
|
case PCI_SIZE_32:
|
|
|
|
default:
|
2015-11-27 02:51:26 +00:00
|
|
|
return 4;
|
2015-11-27 02:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:26 +00:00
|
|
|
static int pci_field_width(enum pci_size_t size)
|
|
|
|
{
|
|
|
|
return pci_byte_size(size) * 2;
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:29 +00:00
|
|
|
static void pci_show_regs(struct udevice *dev, struct pci_reg_info *regs)
|
|
|
|
{
|
|
|
|
for (; regs->name; regs++) {
|
|
|
|
unsigned long val;
|
|
|
|
|
|
|
|
dm_pci_read_config(dev, regs->offset, &val, regs->size);
|
|
|
|
printf(" %s =%*s%#.*lx\n", regs->name,
|
|
|
|
(int)(28 - strlen(regs->name)), "",
|
|
|
|
pci_field_width(regs->size), val);
|
|
|
|
}
|
|
|
|
}
|
2015-11-27 02:51:20 +00:00
|
|
|
|
2021-09-17 12:11:22 +00:00
|
|
|
static int pci_bar_show(struct udevice *dev)
|
2016-12-01 15:14:18 +00:00
|
|
|
{
|
|
|
|
u8 header_type;
|
|
|
|
int bar_cnt, bar_id, mem_type;
|
|
|
|
bool is_64, is_io;
|
|
|
|
u32 base_low, base_high;
|
|
|
|
u32 size_low, size_high;
|
|
|
|
u64 base, size;
|
|
|
|
u32 reg_addr;
|
|
|
|
int prefetchable;
|
|
|
|
|
|
|
|
dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
|
2021-10-07 12:51:00 +00:00
|
|
|
header_type &= 0x7f;
|
2016-12-01 15:14:18 +00:00
|
|
|
|
|
|
|
if (header_type == PCI_HEADER_TYPE_CARDBUS) {
|
|
|
|
printf("CardBus doesn't support BARs\n");
|
|
|
|
return -ENOSYS;
|
2021-10-07 12:51:00 +00:00
|
|
|
} else if (header_type != PCI_HEADER_TYPE_NORMAL &&
|
|
|
|
header_type != PCI_HEADER_TYPE_BRIDGE) {
|
|
|
|
printf("unknown header type\n");
|
|
|
|
return -ENOSYS;
|
2016-12-01 15:14:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bar_cnt = (header_type == PCI_HEADER_TYPE_NORMAL) ? 6 : 2;
|
|
|
|
|
|
|
|
printf("ID Base Size Width Type\n");
|
|
|
|
printf("----------------------------------------------------------\n");
|
|
|
|
|
|
|
|
bar_id = 0;
|
|
|
|
reg_addr = PCI_BASE_ADDRESS_0;
|
|
|
|
while (bar_cnt) {
|
|
|
|
dm_pci_read_config32(dev, reg_addr, &base_low);
|
|
|
|
dm_pci_write_config32(dev, reg_addr, 0xffffffff);
|
|
|
|
dm_pci_read_config32(dev, reg_addr, &size_low);
|
|
|
|
dm_pci_write_config32(dev, reg_addr, base_low);
|
|
|
|
reg_addr += 4;
|
|
|
|
|
|
|
|
base = base_low & ~0xf;
|
|
|
|
size = size_low & ~0xf;
|
|
|
|
base_high = 0x0;
|
|
|
|
size_high = 0xffffffff;
|
|
|
|
is_64 = 0;
|
|
|
|
prefetchable = base_low & PCI_BASE_ADDRESS_MEM_PREFETCH;
|
|
|
|
is_io = base_low & PCI_BASE_ADDRESS_SPACE_IO;
|
|
|
|
mem_type = base_low & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
|
|
|
|
|
|
|
|
if (mem_type == PCI_BASE_ADDRESS_MEM_TYPE_64) {
|
|
|
|
dm_pci_read_config32(dev, reg_addr, &base_high);
|
|
|
|
dm_pci_write_config32(dev, reg_addr, 0xffffffff);
|
|
|
|
dm_pci_read_config32(dev, reg_addr, &size_high);
|
|
|
|
dm_pci_write_config32(dev, reg_addr, base_high);
|
|
|
|
bar_cnt--;
|
|
|
|
reg_addr += 4;
|
|
|
|
is_64 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
base = base | ((u64)base_high << 32);
|
|
|
|
size = size | ((u64)size_high << 32);
|
|
|
|
|
|
|
|
if ((!is_64 && size_low) || (is_64 && size)) {
|
|
|
|
size = ~size + 1;
|
2019-08-23 01:56:55 +00:00
|
|
|
printf(" %d %#018llx %#018llx %d %s %s\n",
|
2017-05-27 13:38:12 +00:00
|
|
|
bar_id, (unsigned long long)base,
|
|
|
|
(unsigned long long)size, is_64 ? 64 : 32,
|
2016-12-01 15:14:18 +00:00
|
|
|
is_io ? "I/O" : "MEM",
|
|
|
|
prefetchable ? "Prefetchable" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
bar_id++;
|
|
|
|
bar_cnt--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:20 +00:00
|
|
|
static struct pci_reg_info regs_start[] = {
|
|
|
|
{ "vendor ID", PCI_SIZE_16, PCI_VENDOR_ID },
|
|
|
|
{ "device ID", PCI_SIZE_16, PCI_DEVICE_ID },
|
|
|
|
{ "command register ID", PCI_SIZE_16, PCI_COMMAND },
|
|
|
|
{ "status register", PCI_SIZE_16, PCI_STATUS },
|
|
|
|
{ "revision ID", PCI_SIZE_8, PCI_REVISION_ID },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_reg_info regs_rest[] = {
|
|
|
|
{ "sub class code", PCI_SIZE_8, PCI_CLASS_SUB_CODE },
|
|
|
|
{ "programming interface", PCI_SIZE_8, PCI_CLASS_PROG },
|
|
|
|
{ "cache line", PCI_SIZE_8, PCI_CACHE_LINE_SIZE },
|
|
|
|
{ "latency time", PCI_SIZE_8, PCI_LATENCY_TIMER },
|
|
|
|
{ "header type", PCI_SIZE_8, PCI_HEADER_TYPE },
|
|
|
|
{ "BIST", PCI_SIZE_8, PCI_BIST },
|
|
|
|
{ "base address 0", PCI_SIZE_32, PCI_BASE_ADDRESS_0 },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_reg_info regs_normal[] = {
|
|
|
|
{ "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
|
|
|
|
{ "base address 2", PCI_SIZE_32, PCI_BASE_ADDRESS_2 },
|
|
|
|
{ "base address 3", PCI_SIZE_32, PCI_BASE_ADDRESS_3 },
|
|
|
|
{ "base address 4", PCI_SIZE_32, PCI_BASE_ADDRESS_4 },
|
|
|
|
{ "base address 5", PCI_SIZE_32, PCI_BASE_ADDRESS_5 },
|
|
|
|
{ "cardBus CIS pointer", PCI_SIZE_32, PCI_CARDBUS_CIS },
|
|
|
|
{ "sub system vendor ID", PCI_SIZE_16, PCI_SUBSYSTEM_VENDOR_ID },
|
|
|
|
{ "sub system ID", PCI_SIZE_16, PCI_SUBSYSTEM_ID },
|
|
|
|
{ "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS },
|
|
|
|
{ "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
|
|
|
|
{ "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
|
|
|
|
{ "min Grant", PCI_SIZE_8, PCI_MIN_GNT },
|
|
|
|
{ "max Latency", PCI_SIZE_8, PCI_MAX_LAT },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_reg_info regs_bridge[] = {
|
|
|
|
{ "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 },
|
|
|
|
{ "primary bus number", PCI_SIZE_8, PCI_PRIMARY_BUS },
|
|
|
|
{ "secondary bus number", PCI_SIZE_8, PCI_SECONDARY_BUS },
|
|
|
|
{ "subordinate bus number", PCI_SIZE_8, PCI_SUBORDINATE_BUS },
|
|
|
|
{ "secondary latency timer", PCI_SIZE_8, PCI_SEC_LATENCY_TIMER },
|
|
|
|
{ "IO base", PCI_SIZE_8, PCI_IO_BASE },
|
|
|
|
{ "IO limit", PCI_SIZE_8, PCI_IO_LIMIT },
|
|
|
|
{ "secondary status", PCI_SIZE_16, PCI_SEC_STATUS },
|
|
|
|
{ "memory base", PCI_SIZE_16, PCI_MEMORY_BASE },
|
|
|
|
{ "memory limit", PCI_SIZE_16, PCI_MEMORY_LIMIT },
|
|
|
|
{ "prefetch memory base", PCI_SIZE_16, PCI_PREF_MEMORY_BASE },
|
|
|
|
{ "prefetch memory limit", PCI_SIZE_16, PCI_PREF_MEMORY_LIMIT },
|
|
|
|
{ "prefetch memory base upper", PCI_SIZE_32, PCI_PREF_BASE_UPPER32 },
|
|
|
|
{ "prefetch memory limit upper", PCI_SIZE_32, PCI_PREF_LIMIT_UPPER32 },
|
|
|
|
{ "IO base upper 16 bits", PCI_SIZE_16, PCI_IO_BASE_UPPER16 },
|
|
|
|
{ "IO limit upper 16 bits", PCI_SIZE_16, PCI_IO_LIMIT_UPPER16 },
|
|
|
|
{ "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS1 },
|
|
|
|
{ "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
|
|
|
|
{ "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
|
|
|
|
{ "bridge control", PCI_SIZE_16, PCI_BRIDGE_CONTROL },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_reg_info regs_cardbus[] = {
|
|
|
|
{ "capabilities", PCI_SIZE_8, PCI_CB_CAPABILITY_LIST },
|
|
|
|
{ "secondary status", PCI_SIZE_16, PCI_CB_SEC_STATUS },
|
|
|
|
{ "primary bus number", PCI_SIZE_8, PCI_CB_PRIMARY_BUS },
|
|
|
|
{ "CardBus number", PCI_SIZE_8, PCI_CB_CARD_BUS },
|
|
|
|
{ "subordinate bus number", PCI_SIZE_8, PCI_CB_SUBORDINATE_BUS },
|
|
|
|
{ "CardBus latency timer", PCI_SIZE_8, PCI_CB_LATENCY_TIMER },
|
|
|
|
{ "CardBus memory base 0", PCI_SIZE_32, PCI_CB_MEMORY_BASE_0 },
|
|
|
|
{ "CardBus memory limit 0", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_0 },
|
|
|
|
{ "CardBus memory base 1", PCI_SIZE_32, PCI_CB_MEMORY_BASE_1 },
|
|
|
|
{ "CardBus memory limit 1", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_1 },
|
|
|
|
{ "CardBus IO base 0", PCI_SIZE_16, PCI_CB_IO_BASE_0 },
|
|
|
|
{ "CardBus IO base high 0", PCI_SIZE_16, PCI_CB_IO_BASE_0_HI },
|
|
|
|
{ "CardBus IO limit 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0 },
|
|
|
|
{ "CardBus IO limit high 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0_HI },
|
|
|
|
{ "CardBus IO base 1", PCI_SIZE_16, PCI_CB_IO_BASE_1 },
|
|
|
|
{ "CardBus IO base high 1", PCI_SIZE_16, PCI_CB_IO_BASE_1_HI },
|
|
|
|
{ "CardBus IO limit 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1 },
|
|
|
|
{ "CardBus IO limit high 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1_HI },
|
|
|
|
{ "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE },
|
|
|
|
{ "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN },
|
|
|
|
{ "bridge control", PCI_SIZE_16, PCI_CB_BRIDGE_CONTROL },
|
|
|
|
{ "subvendor ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_VENDOR_ID },
|
|
|
|
{ "subdevice ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_ID },
|
|
|
|
{ "PC Card 16bit base address", PCI_SIZE_32, PCI_CB_LEGACY_MODE_BASE },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2015-11-27 02:51:25 +00:00
|
|
|
/**
|
|
|
|
* pci_header_show() - Show the header of the specified PCI device.
|
2002-11-03 00:24:07 +00:00
|
|
|
*
|
2015-11-27 02:51:25 +00:00
|
|
|
* @dev: Bus+Device+Function number
|
2002-11-03 00:24:07 +00:00
|
|
|
*/
|
2021-09-17 12:11:23 +00:00
|
|
|
static void pci_header_show(struct udevice *dev)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2015-11-27 02:51:29 +00:00
|
|
|
unsigned long class, header_type;
|
|
|
|
|
|
|
|
dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8);
|
|
|
|
dm_pci_read_config(dev, PCI_HEADER_TYPE, &header_type, PCI_SIZE_8);
|
2015-11-27 02:51:20 +00:00
|
|
|
pci_show_regs(dev, regs_start);
|
2015-11-27 02:51:29 +00:00
|
|
|
printf(" class code = 0x%.2x (%s)\n", (int)class,
|
2015-11-27 02:51:20 +00:00
|
|
|
pci_class_str(class));
|
|
|
|
pci_show_regs(dev, regs_rest);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2021-10-07 12:51:01 +00:00
|
|
|
switch (header_type & 0x7f) {
|
2002-12-07 00:20:59 +00:00
|
|
|
case PCI_HEADER_TYPE_NORMAL: /* "normal" PCI device */
|
2015-11-27 02:51:20 +00:00
|
|
|
pci_show_regs(dev, regs_normal);
|
2002-12-07 00:20:59 +00:00
|
|
|
break;
|
|
|
|
case PCI_HEADER_TYPE_BRIDGE: /* PCI-to-PCI bridge */
|
2015-11-27 02:51:20 +00:00
|
|
|
pci_show_regs(dev, regs_bridge);
|
2002-12-07 00:20:59 +00:00
|
|
|
break;
|
|
|
|
case PCI_HEADER_TYPE_CARDBUS: /* PCI-to-CardBus bridge */
|
2015-11-27 02:51:20 +00:00
|
|
|
pci_show_regs(dev, regs_cardbus);
|
2002-12-07 00:20:59 +00:00
|
|
|
break;
|
2003-06-27 21:31:46 +00:00
|
|
|
|
2002-12-07 00:20:59 +00:00
|
|
|
default:
|
|
|
|
printf("unknown header\n");
|
2003-06-27 21:31:46 +00:00
|
|
|
break;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-17 15:38:40 +00:00
|
|
|
static void pciinfo_header(bool short_listing)
|
2015-11-27 02:51:28 +00:00
|
|
|
{
|
|
|
|
if (short_listing) {
|
|
|
|
printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n");
|
|
|
|
printf("_____________________________________________________________\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:29 +00:00
|
|
|
/**
|
|
|
|
* pci_header_show_brief() - Show the short-form PCI device header
|
|
|
|
*
|
|
|
|
* Reads and prints the header of the specified PCI device in short form.
|
|
|
|
*
|
|
|
|
* @dev: PCI device to show
|
|
|
|
*/
|
|
|
|
static void pci_header_show_brief(struct udevice *dev)
|
|
|
|
{
|
|
|
|
ulong vendor, device;
|
|
|
|
ulong class, subclass;
|
|
|
|
|
|
|
|
dm_pci_read_config(dev, PCI_VENDOR_ID, &vendor, PCI_SIZE_16);
|
|
|
|
dm_pci_read_config(dev, PCI_DEVICE_ID, &device, PCI_SIZE_16);
|
|
|
|
dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8);
|
|
|
|
dm_pci_read_config(dev, PCI_CLASS_SUB_CODE, &subclass, PCI_SIZE_8);
|
|
|
|
|
|
|
|
printf("0x%.4lx 0x%.4lx %-23s 0x%.2lx\n",
|
|
|
|
vendor, device,
|
|
|
|
pci_class_str(class), subclass);
|
|
|
|
}
|
|
|
|
|
2022-01-17 15:38:40 +00:00
|
|
|
static void pciinfo(struct udevice *bus, bool short_listing, bool multi)
|
2015-11-27 02:51:29 +00:00
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
2022-01-17 15:38:40 +00:00
|
|
|
if (!multi)
|
|
|
|
printf("Scanning PCI devices on bus %d\n", dev_seq(bus));
|
|
|
|
|
|
|
|
if (!multi || dev_seq(bus) == 0)
|
|
|
|
pciinfo_header(short_listing);
|
2015-11-27 02:51:29 +00:00
|
|
|
|
|
|
|
for (device_find_first_child(bus, &dev);
|
|
|
|
dev;
|
|
|
|
device_find_next_child(&dev)) {
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pci_child_plat *pplat;
|
2015-11-27 02:51:29 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
pplat = dev_get_parent_plat(dev);
|
2015-11-27 02:51:29 +00:00
|
|
|
if (short_listing) {
|
2020-12-17 04:20:07 +00:00
|
|
|
printf("%02x.%02x.%02x ", dev_seq(bus),
|
2015-11-27 02:51:29 +00:00
|
|
|
PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn));
|
|
|
|
pci_header_show_brief(dev);
|
|
|
|
} else {
|
2020-12-17 04:20:07 +00:00
|
|
|
printf("\nFound PCI device %02x.%02x.%02x:\n",
|
|
|
|
dev_seq(bus),
|
2015-11-27 02:51:29 +00:00
|
|
|
PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn));
|
|
|
|
pci_header_show(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:25 +00:00
|
|
|
/**
|
|
|
|
* get_pci_dev() - Convert the "bus.device.function" identifier into a number
|
|
|
|
*
|
|
|
|
* @name: Device string in the form "bus.device.function" where each is in hex
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: encoded pci_dev_t or -1 if the string was invalid
|
2002-11-03 00:24:07 +00:00
|
|
|
*/
|
2015-11-27 02:51:25 +00:00
|
|
|
static pci_dev_t get_pci_dev(char *name)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
|
|
|
char cnum[12];
|
|
|
|
int len, i, iold, n;
|
|
|
|
int bdfs[3] = {0,0,0};
|
|
|
|
|
|
|
|
len = strlen(name);
|
|
|
|
if (len > 8)
|
|
|
|
return -1;
|
|
|
|
for (i = 0, iold = 0, n = 0; i < len; i++) {
|
|
|
|
if (name[i] == '.') {
|
|
|
|
memcpy(cnum, &name[iold], i - iold);
|
|
|
|
cnum[i - iold] = '\0';
|
2021-07-24 15:03:29 +00:00
|
|
|
bdfs[n++] = hextoul(cnum, NULL);
|
2002-11-03 00:24:07 +00:00
|
|
|
iold = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strcpy(cnum, &name[iold]);
|
|
|
|
if (n == 0)
|
|
|
|
n = 1;
|
2021-07-24 15:03:29 +00:00
|
|
|
bdfs[n] = hextoul(cnum, NULL);
|
2015-11-27 02:51:25 +00:00
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
return PCI_BDF(bdfs[0], bdfs[1], bdfs[2]);
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:29 +00:00
|
|
|
static int pci_cfg_display(struct udevice *dev, ulong addr,
|
|
|
|
enum pci_size_t size, ulong length)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
|
|
|
#define DISP_LINE_LEN 16
|
|
|
|
ulong i, nbytes, linebytes;
|
2015-11-27 02:51:26 +00:00
|
|
|
int byte_size;
|
2002-11-03 00:24:07 +00:00
|
|
|
int rc = 0;
|
|
|
|
|
2015-11-27 02:51:26 +00:00
|
|
|
byte_size = pci_byte_size(size);
|
2002-11-03 00:24:07 +00:00
|
|
|
if (length == 0)
|
2015-11-27 02:51:26 +00:00
|
|
|
length = 0x40 / byte_size; /* Standard PCI config space */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2022-07-03 10:48:06 +00:00
|
|
|
if (addr >= 4096)
|
|
|
|
return 1;
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
/* Print the lines.
|
|
|
|
* once, and all accesses are with the specified bus width.
|
|
|
|
*/
|
2015-11-27 02:51:26 +00:00
|
|
|
nbytes = length * byte_size;
|
2002-11-03 00:24:07 +00:00
|
|
|
do {
|
|
|
|
printf("%08lx:", addr);
|
2015-11-27 02:51:26 +00:00
|
|
|
linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes;
|
|
|
|
for (i = 0; i < linebytes; i += byte_size) {
|
|
|
|
unsigned long val;
|
|
|
|
|
2015-11-27 02:51:29 +00:00
|
|
|
dm_pci_read_config(dev, addr, &val, size);
|
2015-11-27 02:51:26 +00:00
|
|
|
printf(" %0*lx", pci_field_width(size), val);
|
|
|
|
addr += byte_size;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
nbytes -= linebytes;
|
|
|
|
if (ctrlc()) {
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-03 10:48:06 +00:00
|
|
|
} while (nbytes > 0 && addr < 4096);
|
|
|
|
|
|
|
|
if (rc == 0 && nbytes > 0)
|
|
|
|
return 1;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:29 +00:00
|
|
|
static int pci_cfg_modify(struct udevice *dev, ulong addr, ulong size,
|
2015-11-27 02:51:26 +00:00
|
|
|
ulong value, int incrflag)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
|
|
|
ulong i;
|
|
|
|
int nbytes;
|
2015-11-27 02:51:26 +00:00
|
|
|
ulong val;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2022-07-03 10:48:06 +00:00
|
|
|
if (addr >= 4096)
|
|
|
|
return 1;
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
/* Print the address, followed by value. Then accept input for
|
|
|
|
* the next value. A non-converted value exits.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
printf("%08lx:", addr);
|
2015-11-27 02:51:29 +00:00
|
|
|
dm_pci_read_config(dev, addr, &val, size);
|
2015-11-27 02:51:26 +00:00
|
|
|
printf(" %0*lx", pci_field_width(size), val);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2014-04-11 02:01:27 +00:00
|
|
|
nbytes = cli_readline(" ? ");
|
2002-11-03 00:24:07 +00:00
|
|
|
if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
|
|
|
|
/* <CR> pressed as only input, don't modify current
|
|
|
|
* location and move to next. "-" pressed will go back.
|
|
|
|
*/
|
|
|
|
if (incrflag)
|
|
|
|
addr += nbytes ? -size : size;
|
|
|
|
nbytes = 1;
|
2014-04-11 02:01:31 +00:00
|
|
|
/* good enough to not time out */
|
|
|
|
bootretry_reset_cmd_timeout();
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
#ifdef CONFIG_BOOT_RETRY_TIME
|
|
|
|
else if (nbytes == -2) {
|
|
|
|
break; /* timed out, exit the command */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
char *endp;
|
2021-07-24 15:03:29 +00:00
|
|
|
i = hextoul(console_buffer, &endp);
|
2002-11-03 00:24:07 +00:00
|
|
|
nbytes = endp - console_buffer;
|
|
|
|
if (nbytes) {
|
|
|
|
/* good enough to not time out
|
|
|
|
*/
|
2014-04-11 02:01:31 +00:00
|
|
|
bootretry_reset_cmd_timeout();
|
2015-11-27 02:51:29 +00:00
|
|
|
dm_pci_write_config(dev, addr, i, size);
|
2002-11-03 00:24:07 +00:00
|
|
|
if (incrflag)
|
|
|
|
addr += size;
|
|
|
|
}
|
|
|
|
}
|
2022-07-03 10:48:06 +00:00
|
|
|
} while (nbytes && addr < 4096);
|
|
|
|
|
|
|
|
if (nbytes)
|
|
|
|
return 1;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-08 19:10:06 +00:00
|
|
|
static const struct pci_flag_info {
|
|
|
|
uint flag;
|
|
|
|
const char *name;
|
|
|
|
} pci_flag_info[] = {
|
|
|
|
{ PCI_REGION_IO, "io" },
|
|
|
|
{ PCI_REGION_PREFETCH, "prefetch" },
|
|
|
|
{ PCI_REGION_SYS_MEMORY, "sysmem" },
|
|
|
|
{ PCI_REGION_RO, "readonly" },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void pci_show_regions(struct udevice *bus)
|
|
|
|
{
|
2022-01-17 15:38:38 +00:00
|
|
|
struct pci_controller *hose = dev_get_uclass_priv(pci_get_controller(bus));
|
2017-04-08 19:10:06 +00:00
|
|
|
const struct pci_region *reg;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (!hose) {
|
|
|
|
printf("Bus '%s' is not a PCI controller\n", bus->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-17 15:38:38 +00:00
|
|
|
printf("Buses %02x-%02x\n", hose->first_busno, hose->last_busno);
|
2019-08-23 01:56:55 +00:00
|
|
|
printf("# %-18s %-18s %-18s %s\n", "Bus start", "Phys start", "Size",
|
2017-04-08 19:10:06 +00:00
|
|
|
"Flags");
|
|
|
|
for (i = 0, reg = hose->regions; i < hose->region_count; i++, reg++) {
|
2019-08-23 01:56:55 +00:00
|
|
|
printf("%d %#018llx %#018llx %#018llx ", i,
|
2017-04-08 19:10:06 +00:00
|
|
|
(unsigned long long)reg->bus_start,
|
|
|
|
(unsigned long long)reg->phys_start,
|
|
|
|
(unsigned long long)reg->size);
|
|
|
|
if (!(reg->flags & PCI_REGION_TYPE))
|
|
|
|
printf("mem ");
|
|
|
|
for (j = 0; j < ARRAY_SIZE(pci_flag_info); j++) {
|
|
|
|
if (reg->flags & pci_flag_info[j].flag)
|
|
|
|
printf("%s ", pci_flag_info[j].name);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
/* PCI Configuration Space access commands
|
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
* pci display[.b, .w, .l] bus.device.function} [addr] [len]
|
|
|
|
* pci next[.b, .w, .l] bus.device.function [addr]
|
|
|
|
* pci modify[.b, .w, .l] bus.device.function [addr]
|
|
|
|
* pci write[.b, .w, .l] bus.device.function addr value
|
|
|
|
*/
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2015-11-27 02:51:26 +00:00
|
|
|
ulong addr = 0, value = 0, cmd_size = 0;
|
|
|
|
enum pci_size_t size = PCI_SIZE_32;
|
2015-11-27 02:51:29 +00:00
|
|
|
struct udevice *dev, *bus;
|
2022-01-17 15:38:40 +00:00
|
|
|
int busnum = -1;
|
2002-11-03 00:24:07 +00:00
|
|
|
pci_dev_t bdf = 0;
|
|
|
|
char cmd = 's';
|
2015-11-27 02:51:18 +00:00
|
|
|
int ret = 0;
|
2022-01-17 15:38:40 +00:00
|
|
|
char *endp;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
cmd = argv[1][0];
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case 'd': /* display */
|
|
|
|
case 'n': /* next */
|
|
|
|
case 'm': /* modify */
|
|
|
|
case 'w': /* write */
|
|
|
|
/* Check for a size specification. */
|
2015-11-27 02:51:26 +00:00
|
|
|
cmd_size = cmd_get_data_size(argv[1], 4);
|
|
|
|
size = (cmd_size == 4) ? PCI_SIZE_32 : cmd_size - 1;
|
2002-11-03 00:24:07 +00:00
|
|
|
if (argc > 3)
|
2021-07-24 15:03:29 +00:00
|
|
|
addr = hextoul(argv[3], NULL);
|
2002-11-03 00:24:07 +00:00
|
|
|
if (argc > 4)
|
2021-07-24 15:03:29 +00:00
|
|
|
value = hextoul(argv[4], NULL);
|
2023-04-01 07:43:33 +00:00
|
|
|
fallthrough;
|
2002-11-03 00:24:07 +00:00
|
|
|
case 'h': /* header */
|
2016-12-01 15:14:18 +00:00
|
|
|
case 'b': /* bars */
|
2002-11-03 00:24:07 +00:00
|
|
|
if (argc < 3)
|
|
|
|
goto usage;
|
|
|
|
if ((bdf = get_pci_dev(argv[2])) == -1)
|
|
|
|
return 1;
|
|
|
|
break;
|
2010-10-22 05:20:23 +00:00
|
|
|
case 'e':
|
Implement "pci enum" command for CONFIG_DM_PCI
With CONFIG_DM_PCI enabled, PCI buses are not enumerated at boot, as they
are without that config option enabled. No command exists to enumerate the
PCI buses. Hence, unless some board-specific code causes PCI enumeration,
PCI-based Ethernet devices are not detected, and network access is not
available.
This patch implements "pci enum" in the CONFIG_DM_PCI case, thus giving a
mechanism whereby PCI can be enumerated.
do_pci()'s handling of case 'e' is moved into a single location before the
dev variable is assigned, in order to skip calculation of dev. The enum
sub-command doesn't need the dev value, and skipping its calculation
avoids an irrelevant error being printed.
Using a command to initialize PCI like this has a disadvantage relative to
enumerating PCI at boot. In particular, Ethernet devices are not probed
during PCI enumeration, but only when used. This defers setting variables
such as ethact, ethaddr, etc. until the first network-related command is
executed. Hopefully this will not cause further issues. Perhaps in the
long term, we need a "net start/enum" command too?
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2016-01-26 18:10:11 +00:00
|
|
|
pci_init();
|
|
|
|
return 0;
|
2017-04-08 19:10:06 +00:00
|
|
|
case 'r': /* no break */
|
2002-11-03 00:24:07 +00:00
|
|
|
default: /* scan bus */
|
|
|
|
value = 1; /* short listing */
|
|
|
|
if (argc > 1) {
|
2017-04-08 19:10:06 +00:00
|
|
|
if (cmd != 'r' && argv[argc-1][0] == 'l') {
|
2002-11-03 00:24:07 +00:00
|
|
|
value = 0;
|
|
|
|
argc--;
|
|
|
|
}
|
2022-01-17 15:38:38 +00:00
|
|
|
if (argc > 2 || (argc > 1 && cmd != 'r' && argv[1][0] != 's')) {
|
2022-01-17 15:38:40 +00:00
|
|
|
if (argv[argc - 1][0] != '*') {
|
|
|
|
busnum = hextoul(argv[argc - 1], &endp);
|
|
|
|
if (*endp)
|
|
|
|
goto usage;
|
|
|
|
}
|
2022-01-17 15:38:39 +00:00
|
|
|
argc--;
|
2022-01-17 15:38:38 +00:00
|
|
|
}
|
2022-01-17 15:38:39 +00:00
|
|
|
if (cmd == 'r' && argc > 2)
|
|
|
|
goto usage;
|
|
|
|
else if (cmd != 'r' && (argc > 2 || (argc == 2 && argv[1][0] != 's')))
|
|
|
|
goto usage;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
2022-01-17 15:38:40 +00:00
|
|
|
if (busnum == -1) {
|
|
|
|
if (cmd != 'r') {
|
|
|
|
for (busnum = 0;
|
|
|
|
uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0;
|
|
|
|
busnum++)
|
|
|
|
pciinfo(bus, value, true);
|
|
|
|
} else {
|
|
|
|
for (busnum = 0;
|
|
|
|
uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0;
|
|
|
|
busnum++) {
|
|
|
|
/* Regions are controller specific so skip non-root buses */
|
|
|
|
if (device_is_on_pci_bus(bus))
|
|
|
|
continue;
|
|
|
|
pci_show_regions(bus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-27 02:51:29 +00:00
|
|
|
ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus);
|
|
|
|
if (ret) {
|
|
|
|
printf("No such bus\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
2017-04-08 19:10:06 +00:00
|
|
|
if (cmd == 'r')
|
|
|
|
pci_show_regions(bus);
|
|
|
|
else
|
2022-01-17 15:38:40 +00:00
|
|
|
pciinfo(bus, value, false);
|
2002-11-03 00:24:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-29 20:17:48 +00:00
|
|
|
ret = dm_pci_bus_find_bdf(bdf, &dev);
|
2015-11-27 02:51:29 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("No such device\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
2015-11-27 02:51:27 +00:00
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
switch (argv[1][0]) {
|
|
|
|
case 'h': /* header */
|
2015-11-27 02:51:27 +00:00
|
|
|
pci_header_show(dev);
|
2015-11-27 02:51:18 +00:00
|
|
|
break;
|
2002-11-03 00:24:07 +00:00
|
|
|
case 'd': /* display */
|
2015-11-27 02:51:27 +00:00
|
|
|
return pci_cfg_display(dev, addr, size, value);
|
2002-11-03 00:24:07 +00:00
|
|
|
case 'n': /* next */
|
|
|
|
if (argc < 4)
|
|
|
|
goto usage;
|
2015-11-27 02:51:27 +00:00
|
|
|
ret = pci_cfg_modify(dev, addr, size, value, 0);
|
2015-11-27 02:51:18 +00:00
|
|
|
break;
|
2002-11-03 00:24:07 +00:00
|
|
|
case 'm': /* modify */
|
|
|
|
if (argc < 4)
|
|
|
|
goto usage;
|
2015-11-27 02:51:27 +00:00
|
|
|
ret = pci_cfg_modify(dev, addr, size, value, 1);
|
2015-11-27 02:51:18 +00:00
|
|
|
break;
|
2002-11-03 00:24:07 +00:00
|
|
|
case 'w': /* write */
|
|
|
|
if (argc < 5)
|
|
|
|
goto usage;
|
2015-11-27 02:51:29 +00:00
|
|
|
ret = dm_pci_write_config(dev, addr, value, size);
|
2015-11-27 02:51:18 +00:00
|
|
|
break;
|
2016-12-01 15:14:18 +00:00
|
|
|
case 'b': /* bars */
|
|
|
|
return pci_bar_show(dev);
|
2015-11-27 02:51:18 +00:00
|
|
|
default:
|
|
|
|
ret = CMD_RET_USAGE;
|
|
|
|
break;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 02:51:18 +00:00
|
|
|
return ret;
|
2002-11-03 00:24:07 +00:00
|
|
|
usage:
|
2011-12-10 08:44:01 +00:00
|
|
|
return CMD_RET_USAGE;
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2003-06-27 21:31:46 +00:00
|
|
|
/***************************************************/
|
|
|
|
|
2023-10-07 19:13:08 +00:00
|
|
|
U_BOOT_LONGHELP(pci,
|
2022-01-17 15:38:40 +00:00
|
|
|
"[bus|*] [long]\n"
|
2003-06-27 21:31:46 +00:00
|
|
|
" - short or long list of PCI devices on bus 'bus'\n"
|
2010-10-22 05:20:23 +00:00
|
|
|
"pci enum\n"
|
Implement "pci enum" command for CONFIG_DM_PCI
With CONFIG_DM_PCI enabled, PCI buses are not enumerated at boot, as they
are without that config option enabled. No command exists to enumerate the
PCI buses. Hence, unless some board-specific code causes PCI enumeration,
PCI-based Ethernet devices are not detected, and network access is not
available.
This patch implements "pci enum" in the CONFIG_DM_PCI case, thus giving a
mechanism whereby PCI can be enumerated.
do_pci()'s handling of case 'e' is moved into a single location before the
dev variable is assigned, in order to skip calculation of dev. The enum
sub-command doesn't need the dev value, and skipping its calculation
avoids an irrelevant error being printed.
Using a command to initialize PCI like this has a disadvantage relative to
enumerating PCI at boot. In particular, Ethernet devices are not probed
during PCI enumeration, but only when used. This defers setting variables
such as ethact, ethaddr, etc. until the first network-related command is
executed. Hopefully this will not cause further issues. Perhaps in the
long term, we need a "net start/enum" command too?
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2016-01-26 18:10:11 +00:00
|
|
|
" - Enumerate PCI buses\n"
|
2003-06-27 21:31:46 +00:00
|
|
|
"pci header b.d.f\n"
|
|
|
|
" - show header of PCI device 'bus.device.function'\n"
|
2016-12-01 15:14:18 +00:00
|
|
|
"pci bar b.d.f\n"
|
|
|
|
" - show BARs base and size for device b.d.f'\n"
|
2022-01-17 15:38:40 +00:00
|
|
|
"pci regions [bus|*]\n"
|
2017-04-08 19:10:06 +00:00
|
|
|
" - show PCI regions\n"
|
2003-06-27 21:31:46 +00:00
|
|
|
"pci display[.b, .w, .l] b.d.f [address] [# of objects]\n"
|
|
|
|
" - display PCI configuration space (CFG)\n"
|
|
|
|
"pci next[.b, .w, .l] b.d.f address\n"
|
|
|
|
" - modify, read and keep CFG address\n"
|
|
|
|
"pci modify[.b, .w, .l] b.d.f address\n"
|
|
|
|
" - modify, auto increment CFG address\n"
|
|
|
|
"pci write[.b, .w, .l] b.d.f address value\n"
|
2023-10-07 19:13:08 +00:00
|
|
|
" - write to CFG address");
|
2012-10-29 13:34:31 +00:00
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
pci, 5, 1, do_pci,
|
|
|
|
"list and access PCI Configuration Space", pci_help_text
|
2003-06-27 21:31:46 +00:00
|
|
|
);
|