Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Andreas Heppel <aheppel@sysgo.de> |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 8 | * Wolfgang Grandegger, DENX Software Engineering, wg@denx.de. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * PCI routines |
| 13 | */ |
| 14 | |
| 15 | #include <common.h> |
Simon Glass | 0098e17 | 2014-04-10 20:01:30 -0600 | [diff] [blame] | 16 | #include <bootretry.h> |
Simon Glass | 18d6653 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 17 | #include <cli.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 18 | #include <command.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 19 | #include <console.h> |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 20 | #include <dm.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 21 | #include <init.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 22 | #include <asm/processor.h> |
| 23 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 24 | #include <pci.h> |
| 25 | |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 26 | struct pci_reg_info { |
| 27 | const char *name; |
| 28 | enum pci_size_t size; |
| 29 | u8 offset; |
| 30 | }; |
| 31 | |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 32 | static int pci_byte_size(enum pci_size_t size) |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 33 | { |
| 34 | switch (size) { |
| 35 | case PCI_SIZE_8: |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 36 | return 1; |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 37 | case PCI_SIZE_16: |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 38 | return 2; |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 39 | case PCI_SIZE_32: |
| 40 | default: |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 41 | return 4; |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 45 | static int pci_field_width(enum pci_size_t size) |
| 46 | { |
| 47 | return pci_byte_size(size) * 2; |
| 48 | } |
| 49 | |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 50 | static void pci_show_regs(struct udevice *dev, struct pci_reg_info *regs) |
| 51 | { |
| 52 | for (; regs->name; regs++) { |
| 53 | unsigned long val; |
| 54 | |
| 55 | dm_pci_read_config(dev, regs->offset, &val, regs->size); |
| 56 | printf(" %s =%*s%#.*lx\n", regs->name, |
| 57 | (int)(28 - strlen(regs->name)), "", |
| 58 | pci_field_width(regs->size), val); |
| 59 | } |
| 60 | } |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 61 | |
Vladimir Oltean | f5164f6 | 2021-09-17 15:11:22 +0300 | [diff] [blame] | 62 | static int pci_bar_show(struct udevice *dev) |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 63 | { |
| 64 | u8 header_type; |
| 65 | int bar_cnt, bar_id, mem_type; |
| 66 | bool is_64, is_io; |
| 67 | u32 base_low, base_high; |
| 68 | u32 size_low, size_high; |
| 69 | u64 base, size; |
| 70 | u32 reg_addr; |
| 71 | int prefetchable; |
| 72 | |
| 73 | dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type); |
Pali Rohár | e6335d3 | 2021-10-07 14:51:00 +0200 | [diff] [blame] | 74 | header_type &= 0x7f; |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 75 | |
| 76 | if (header_type == PCI_HEADER_TYPE_CARDBUS) { |
| 77 | printf("CardBus doesn't support BARs\n"); |
| 78 | return -ENOSYS; |
Pali Rohár | e6335d3 | 2021-10-07 14:51:00 +0200 | [diff] [blame] | 79 | } else if (header_type != PCI_HEADER_TYPE_NORMAL && |
| 80 | header_type != PCI_HEADER_TYPE_BRIDGE) { |
| 81 | printf("unknown header type\n"); |
| 82 | return -ENOSYS; |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | bar_cnt = (header_type == PCI_HEADER_TYPE_NORMAL) ? 6 : 2; |
| 86 | |
| 87 | printf("ID Base Size Width Type\n"); |
| 88 | printf("----------------------------------------------------------\n"); |
| 89 | |
| 90 | bar_id = 0; |
| 91 | reg_addr = PCI_BASE_ADDRESS_0; |
| 92 | while (bar_cnt) { |
| 93 | dm_pci_read_config32(dev, reg_addr, &base_low); |
| 94 | dm_pci_write_config32(dev, reg_addr, 0xffffffff); |
| 95 | dm_pci_read_config32(dev, reg_addr, &size_low); |
| 96 | dm_pci_write_config32(dev, reg_addr, base_low); |
| 97 | reg_addr += 4; |
| 98 | |
| 99 | base = base_low & ~0xf; |
| 100 | size = size_low & ~0xf; |
| 101 | base_high = 0x0; |
| 102 | size_high = 0xffffffff; |
| 103 | is_64 = 0; |
| 104 | prefetchable = base_low & PCI_BASE_ADDRESS_MEM_PREFETCH; |
| 105 | is_io = base_low & PCI_BASE_ADDRESS_SPACE_IO; |
| 106 | mem_type = base_low & PCI_BASE_ADDRESS_MEM_TYPE_MASK; |
| 107 | |
| 108 | if (mem_type == PCI_BASE_ADDRESS_MEM_TYPE_64) { |
| 109 | dm_pci_read_config32(dev, reg_addr, &base_high); |
| 110 | dm_pci_write_config32(dev, reg_addr, 0xffffffff); |
| 111 | dm_pci_read_config32(dev, reg_addr, &size_high); |
| 112 | dm_pci_write_config32(dev, reg_addr, base_high); |
| 113 | bar_cnt--; |
| 114 | reg_addr += 4; |
| 115 | is_64 = 1; |
| 116 | } |
| 117 | |
| 118 | base = base | ((u64)base_high << 32); |
| 119 | size = size | ((u64)size_high << 32); |
| 120 | |
| 121 | if ((!is_64 && size_low) || (is_64 && size)) { |
| 122 | size = ~size + 1; |
Kunihiko Hayashi | 4ebeb4c | 2019-08-23 10:56:55 +0900 | [diff] [blame] | 123 | printf(" %d %#018llx %#018llx %d %s %s\n", |
Simon Glass | 84d7f91 | 2017-05-27 07:38:12 -0600 | [diff] [blame] | 124 | bar_id, (unsigned long long)base, |
| 125 | (unsigned long long)size, is_64 ? 64 : 32, |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 126 | is_io ? "I/O" : "MEM", |
| 127 | prefetchable ? "Prefetchable" : ""); |
| 128 | } |
| 129 | |
| 130 | bar_id++; |
| 131 | bar_cnt--; |
| 132 | } |
| 133 | |
| 134 | return 0; |
| 135 | } |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 136 | |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 137 | static struct pci_reg_info regs_start[] = { |
| 138 | { "vendor ID", PCI_SIZE_16, PCI_VENDOR_ID }, |
| 139 | { "device ID", PCI_SIZE_16, PCI_DEVICE_ID }, |
| 140 | { "command register ID", PCI_SIZE_16, PCI_COMMAND }, |
| 141 | { "status register", PCI_SIZE_16, PCI_STATUS }, |
| 142 | { "revision ID", PCI_SIZE_8, PCI_REVISION_ID }, |
| 143 | {}, |
| 144 | }; |
| 145 | |
| 146 | static struct pci_reg_info regs_rest[] = { |
| 147 | { "sub class code", PCI_SIZE_8, PCI_CLASS_SUB_CODE }, |
| 148 | { "programming interface", PCI_SIZE_8, PCI_CLASS_PROG }, |
| 149 | { "cache line", PCI_SIZE_8, PCI_CACHE_LINE_SIZE }, |
| 150 | { "latency time", PCI_SIZE_8, PCI_LATENCY_TIMER }, |
| 151 | { "header type", PCI_SIZE_8, PCI_HEADER_TYPE }, |
| 152 | { "BIST", PCI_SIZE_8, PCI_BIST }, |
| 153 | { "base address 0", PCI_SIZE_32, PCI_BASE_ADDRESS_0 }, |
| 154 | {}, |
| 155 | }; |
| 156 | |
| 157 | static struct pci_reg_info regs_normal[] = { |
| 158 | { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 }, |
| 159 | { "base address 2", PCI_SIZE_32, PCI_BASE_ADDRESS_2 }, |
| 160 | { "base address 3", PCI_SIZE_32, PCI_BASE_ADDRESS_3 }, |
| 161 | { "base address 4", PCI_SIZE_32, PCI_BASE_ADDRESS_4 }, |
| 162 | { "base address 5", PCI_SIZE_32, PCI_BASE_ADDRESS_5 }, |
| 163 | { "cardBus CIS pointer", PCI_SIZE_32, PCI_CARDBUS_CIS }, |
| 164 | { "sub system vendor ID", PCI_SIZE_16, PCI_SUBSYSTEM_VENDOR_ID }, |
| 165 | { "sub system ID", PCI_SIZE_16, PCI_SUBSYSTEM_ID }, |
| 166 | { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS }, |
| 167 | { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE }, |
| 168 | { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN }, |
| 169 | { "min Grant", PCI_SIZE_8, PCI_MIN_GNT }, |
| 170 | { "max Latency", PCI_SIZE_8, PCI_MAX_LAT }, |
| 171 | {}, |
| 172 | }; |
| 173 | |
| 174 | static struct pci_reg_info regs_bridge[] = { |
| 175 | { "base address 1", PCI_SIZE_32, PCI_BASE_ADDRESS_1 }, |
| 176 | { "primary bus number", PCI_SIZE_8, PCI_PRIMARY_BUS }, |
| 177 | { "secondary bus number", PCI_SIZE_8, PCI_SECONDARY_BUS }, |
| 178 | { "subordinate bus number", PCI_SIZE_8, PCI_SUBORDINATE_BUS }, |
| 179 | { "secondary latency timer", PCI_SIZE_8, PCI_SEC_LATENCY_TIMER }, |
| 180 | { "IO base", PCI_SIZE_8, PCI_IO_BASE }, |
| 181 | { "IO limit", PCI_SIZE_8, PCI_IO_LIMIT }, |
| 182 | { "secondary status", PCI_SIZE_16, PCI_SEC_STATUS }, |
| 183 | { "memory base", PCI_SIZE_16, PCI_MEMORY_BASE }, |
| 184 | { "memory limit", PCI_SIZE_16, PCI_MEMORY_LIMIT }, |
| 185 | { "prefetch memory base", PCI_SIZE_16, PCI_PREF_MEMORY_BASE }, |
| 186 | { "prefetch memory limit", PCI_SIZE_16, PCI_PREF_MEMORY_LIMIT }, |
| 187 | { "prefetch memory base upper", PCI_SIZE_32, PCI_PREF_BASE_UPPER32 }, |
| 188 | { "prefetch memory limit upper", PCI_SIZE_32, PCI_PREF_LIMIT_UPPER32 }, |
| 189 | { "IO base upper 16 bits", PCI_SIZE_16, PCI_IO_BASE_UPPER16 }, |
| 190 | { "IO limit upper 16 bits", PCI_SIZE_16, PCI_IO_LIMIT_UPPER16 }, |
| 191 | { "expansion ROM base address", PCI_SIZE_32, PCI_ROM_ADDRESS1 }, |
| 192 | { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE }, |
| 193 | { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN }, |
| 194 | { "bridge control", PCI_SIZE_16, PCI_BRIDGE_CONTROL }, |
| 195 | {}, |
| 196 | }; |
| 197 | |
| 198 | static struct pci_reg_info regs_cardbus[] = { |
| 199 | { "capabilities", PCI_SIZE_8, PCI_CB_CAPABILITY_LIST }, |
| 200 | { "secondary status", PCI_SIZE_16, PCI_CB_SEC_STATUS }, |
| 201 | { "primary bus number", PCI_SIZE_8, PCI_CB_PRIMARY_BUS }, |
| 202 | { "CardBus number", PCI_SIZE_8, PCI_CB_CARD_BUS }, |
| 203 | { "subordinate bus number", PCI_SIZE_8, PCI_CB_SUBORDINATE_BUS }, |
| 204 | { "CardBus latency timer", PCI_SIZE_8, PCI_CB_LATENCY_TIMER }, |
| 205 | { "CardBus memory base 0", PCI_SIZE_32, PCI_CB_MEMORY_BASE_0 }, |
| 206 | { "CardBus memory limit 0", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_0 }, |
| 207 | { "CardBus memory base 1", PCI_SIZE_32, PCI_CB_MEMORY_BASE_1 }, |
| 208 | { "CardBus memory limit 1", PCI_SIZE_32, PCI_CB_MEMORY_LIMIT_1 }, |
| 209 | { "CardBus IO base 0", PCI_SIZE_16, PCI_CB_IO_BASE_0 }, |
| 210 | { "CardBus IO base high 0", PCI_SIZE_16, PCI_CB_IO_BASE_0_HI }, |
| 211 | { "CardBus IO limit 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0 }, |
| 212 | { "CardBus IO limit high 0", PCI_SIZE_16, PCI_CB_IO_LIMIT_0_HI }, |
| 213 | { "CardBus IO base 1", PCI_SIZE_16, PCI_CB_IO_BASE_1 }, |
| 214 | { "CardBus IO base high 1", PCI_SIZE_16, PCI_CB_IO_BASE_1_HI }, |
| 215 | { "CardBus IO limit 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1 }, |
| 216 | { "CardBus IO limit high 1", PCI_SIZE_16, PCI_CB_IO_LIMIT_1_HI }, |
| 217 | { "interrupt line", PCI_SIZE_8, PCI_INTERRUPT_LINE }, |
| 218 | { "interrupt pin", PCI_SIZE_8, PCI_INTERRUPT_PIN }, |
| 219 | { "bridge control", PCI_SIZE_16, PCI_CB_BRIDGE_CONTROL }, |
| 220 | { "subvendor ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_VENDOR_ID }, |
| 221 | { "subdevice ID", PCI_SIZE_16, PCI_CB_SUBSYSTEM_ID }, |
| 222 | { "PC Card 16bit base address", PCI_SIZE_32, PCI_CB_LEGACY_MODE_BASE }, |
| 223 | {}, |
| 224 | }; |
| 225 | |
Simon Glass | c2be070 | 2015-11-26 19:51:25 -0700 | [diff] [blame] | 226 | /** |
| 227 | * pci_header_show() - Show the header of the specified PCI device. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 228 | * |
Simon Glass | c2be070 | 2015-11-26 19:51:25 -0700 | [diff] [blame] | 229 | * @dev: Bus+Device+Function number |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 230 | */ |
Vladimir Oltean | a95f8ee | 2021-09-17 15:11:23 +0300 | [diff] [blame] | 231 | static void pci_header_show(struct udevice *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 232 | { |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 233 | unsigned long class, header_type; |
| 234 | |
| 235 | dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8); |
| 236 | dm_pci_read_config(dev, PCI_HEADER_TYPE, &header_type, PCI_SIZE_8); |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 237 | pci_show_regs(dev, regs_start); |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 238 | printf(" class code = 0x%.2x (%s)\n", (int)class, |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 239 | pci_class_str(class)); |
| 240 | pci_show_regs(dev, regs_rest); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 241 | |
Pali Rohár | 43dad07 | 2021-10-07 14:51:01 +0200 | [diff] [blame] | 242 | switch (header_type & 0x7f) { |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 243 | case PCI_HEADER_TYPE_NORMAL: /* "normal" PCI device */ |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 244 | pci_show_regs(dev, regs_normal); |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 245 | break; |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 246 | case PCI_HEADER_TYPE_BRIDGE: /* PCI-to-PCI bridge */ |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 247 | pci_show_regs(dev, regs_bridge); |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 248 | break; |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 249 | case PCI_HEADER_TYPE_CARDBUS: /* PCI-to-CardBus bridge */ |
Simon Glass | 07a5887 | 2015-11-26 19:51:20 -0700 | [diff] [blame] | 250 | pci_show_regs(dev, regs_cardbus); |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 251 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 252 | |
wdenk | 7c7a23b | 2002-12-07 00:20:59 +0000 | [diff] [blame] | 253 | default: |
| 254 | printf("unknown header\n"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 255 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 259 | static void pciinfo_header(bool short_listing) |
Simon Glass | c4f32bb | 2015-11-26 19:51:28 -0700 | [diff] [blame] | 260 | { |
Simon Glass | c4f32bb | 2015-11-26 19:51:28 -0700 | [diff] [blame] | 261 | if (short_listing) { |
| 262 | printf("BusDevFun VendorId DeviceId Device Class Sub-Class\n"); |
| 263 | printf("_____________________________________________________________\n"); |
| 264 | } |
| 265 | } |
| 266 | |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 267 | /** |
| 268 | * pci_header_show_brief() - Show the short-form PCI device header |
| 269 | * |
| 270 | * Reads and prints the header of the specified PCI device in short form. |
| 271 | * |
| 272 | * @dev: PCI device to show |
| 273 | */ |
| 274 | static void pci_header_show_brief(struct udevice *dev) |
| 275 | { |
| 276 | ulong vendor, device; |
| 277 | ulong class, subclass; |
| 278 | |
| 279 | dm_pci_read_config(dev, PCI_VENDOR_ID, &vendor, PCI_SIZE_16); |
| 280 | dm_pci_read_config(dev, PCI_DEVICE_ID, &device, PCI_SIZE_16); |
| 281 | dm_pci_read_config(dev, PCI_CLASS_CODE, &class, PCI_SIZE_8); |
| 282 | dm_pci_read_config(dev, PCI_CLASS_SUB_CODE, &subclass, PCI_SIZE_8); |
| 283 | |
| 284 | printf("0x%.4lx 0x%.4lx %-23s 0x%.2lx\n", |
| 285 | vendor, device, |
| 286 | pci_class_str(class), subclass); |
| 287 | } |
| 288 | |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 289 | static void pciinfo(struct udevice *bus, bool short_listing, bool multi) |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 290 | { |
| 291 | struct udevice *dev; |
| 292 | |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 293 | if (!multi) |
| 294 | printf("Scanning PCI devices on bus %d\n", dev_seq(bus)); |
| 295 | |
| 296 | if (!multi || dev_seq(bus) == 0) |
| 297 | pciinfo_header(short_listing); |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 298 | |
| 299 | for (device_find_first_child(bus, &dev); |
| 300 | dev; |
| 301 | device_find_next_child(&dev)) { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 302 | struct pci_child_plat *pplat; |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 303 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 304 | pplat = dev_get_parent_plat(dev); |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 305 | if (short_listing) { |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 306 | printf("%02x.%02x.%02x ", dev_seq(bus), |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 307 | PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn)); |
| 308 | pci_header_show_brief(dev); |
| 309 | } else { |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 310 | printf("\nFound PCI device %02x.%02x.%02x:\n", |
| 311 | dev_seq(bus), |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 312 | PCI_DEV(pplat->devfn), PCI_FUNC(pplat->devfn)); |
| 313 | pci_header_show(dev); |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
Simon Glass | c2be070 | 2015-11-26 19:51:25 -0700 | [diff] [blame] | 318 | /** |
| 319 | * get_pci_dev() - Convert the "bus.device.function" identifier into a number |
| 320 | * |
| 321 | * @name: Device string in the form "bus.device.function" where each is in hex |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 322 | * Return: encoded pci_dev_t or -1 if the string was invalid |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 323 | */ |
Simon Glass | c2be070 | 2015-11-26 19:51:25 -0700 | [diff] [blame] | 324 | static pci_dev_t get_pci_dev(char *name) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 325 | { |
| 326 | char cnum[12]; |
| 327 | int len, i, iold, n; |
| 328 | int bdfs[3] = {0,0,0}; |
| 329 | |
| 330 | len = strlen(name); |
| 331 | if (len > 8) |
| 332 | return -1; |
| 333 | for (i = 0, iold = 0, n = 0; i < len; i++) { |
| 334 | if (name[i] == '.') { |
| 335 | memcpy(cnum, &name[iold], i - iold); |
| 336 | cnum[i - iold] = '\0'; |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 337 | bdfs[n++] = hextoul(cnum, NULL); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 338 | iold = i + 1; |
| 339 | } |
| 340 | } |
| 341 | strcpy(cnum, &name[iold]); |
| 342 | if (n == 0) |
| 343 | n = 1; |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 344 | bdfs[n] = hextoul(cnum, NULL); |
Simon Glass | c2be070 | 2015-11-26 19:51:25 -0700 | [diff] [blame] | 345 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 346 | return PCI_BDF(bdfs[0], bdfs[1], bdfs[2]); |
| 347 | } |
| 348 | |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 349 | static int pci_cfg_display(struct udevice *dev, ulong addr, |
| 350 | enum pci_size_t size, ulong length) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 351 | { |
| 352 | #define DISP_LINE_LEN 16 |
| 353 | ulong i, nbytes, linebytes; |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 354 | int byte_size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 355 | int rc = 0; |
| 356 | |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 357 | byte_size = pci_byte_size(size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 358 | if (length == 0) |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 359 | length = 0x40 / byte_size; /* Standard PCI config space */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 360 | |
Pali Rohár | d9f554b | 2022-07-03 12:48:06 +0200 | [diff] [blame] | 361 | if (addr >= 4096) |
| 362 | return 1; |
| 363 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 364 | /* Print the lines. |
| 365 | * once, and all accesses are with the specified bus width. |
| 366 | */ |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 367 | nbytes = length * byte_size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 368 | do { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 369 | printf("%08lx:", addr); |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 370 | linebytes = (nbytes > DISP_LINE_LEN) ? DISP_LINE_LEN : nbytes; |
| 371 | for (i = 0; i < linebytes; i += byte_size) { |
| 372 | unsigned long val; |
| 373 | |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 374 | dm_pci_read_config(dev, addr, &val, size); |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 375 | printf(" %0*lx", pci_field_width(size), val); |
| 376 | addr += byte_size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 377 | } |
| 378 | printf("\n"); |
| 379 | nbytes -= linebytes; |
| 380 | if (ctrlc()) { |
| 381 | rc = 1; |
| 382 | break; |
| 383 | } |
Pali Rohár | d9f554b | 2022-07-03 12:48:06 +0200 | [diff] [blame] | 384 | } while (nbytes > 0 && addr < 4096); |
| 385 | |
| 386 | if (rc == 0 && nbytes > 0) |
| 387 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 388 | |
| 389 | return (rc); |
| 390 | } |
| 391 | |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 392 | static int pci_cfg_modify(struct udevice *dev, ulong addr, ulong size, |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 393 | ulong value, int incrflag) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 394 | { |
| 395 | ulong i; |
| 396 | int nbytes; |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 397 | ulong val; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 398 | |
Pali Rohár | d9f554b | 2022-07-03 12:48:06 +0200 | [diff] [blame] | 399 | if (addr >= 4096) |
| 400 | return 1; |
| 401 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 402 | /* Print the address, followed by value. Then accept input for |
| 403 | * the next value. A non-converted value exits. |
| 404 | */ |
| 405 | do { |
| 406 | printf("%08lx:", addr); |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 407 | dm_pci_read_config(dev, addr, &val, size); |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 408 | printf(" %0*lx", pci_field_width(size), val); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 409 | |
Simon Glass | e1bf824 | 2014-04-10 20:01:27 -0600 | [diff] [blame] | 410 | nbytes = cli_readline(" ? "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 411 | if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { |
| 412 | /* <CR> pressed as only input, don't modify current |
| 413 | * location and move to next. "-" pressed will go back. |
| 414 | */ |
| 415 | if (incrflag) |
| 416 | addr += nbytes ? -size : size; |
| 417 | nbytes = 1; |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 418 | /* good enough to not time out */ |
| 419 | bootretry_reset_cmd_timeout(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | } |
| 421 | #ifdef CONFIG_BOOT_RETRY_TIME |
| 422 | else if (nbytes == -2) { |
| 423 | break; /* timed out, exit the command */ |
| 424 | } |
| 425 | #endif |
| 426 | else { |
| 427 | char *endp; |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 428 | i = hextoul(console_buffer, &endp); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 429 | nbytes = endp - console_buffer; |
| 430 | if (nbytes) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 431 | /* good enough to not time out |
| 432 | */ |
Simon Glass | b26440f | 2014-04-10 20:01:31 -0600 | [diff] [blame] | 433 | bootretry_reset_cmd_timeout(); |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 434 | dm_pci_write_config(dev, addr, i, size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 435 | if (incrflag) |
| 436 | addr += size; |
| 437 | } |
| 438 | } |
Pali Rohár | d9f554b | 2022-07-03 12:48:06 +0200 | [diff] [blame] | 439 | } while (nbytes && addr < 4096); |
| 440 | |
| 441 | if (nbytes) |
| 442 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 447 | static const struct pci_flag_info { |
| 448 | uint flag; |
| 449 | const char *name; |
| 450 | } pci_flag_info[] = { |
| 451 | { PCI_REGION_IO, "io" }, |
| 452 | { PCI_REGION_PREFETCH, "prefetch" }, |
| 453 | { PCI_REGION_SYS_MEMORY, "sysmem" }, |
| 454 | { PCI_REGION_RO, "readonly" }, |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 455 | }; |
| 456 | |
| 457 | static void pci_show_regions(struct udevice *bus) |
| 458 | { |
Pali Rohár | 3932093 | 2022-01-17 16:38:38 +0100 | [diff] [blame] | 459 | struct pci_controller *hose = dev_get_uclass_priv(pci_get_controller(bus)); |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 460 | const struct pci_region *reg; |
| 461 | int i, j; |
| 462 | |
| 463 | if (!hose) { |
| 464 | printf("Bus '%s' is not a PCI controller\n", bus->name); |
| 465 | return; |
| 466 | } |
| 467 | |
Pali Rohár | 3932093 | 2022-01-17 16:38:38 +0100 | [diff] [blame] | 468 | printf("Buses %02x-%02x\n", hose->first_busno, hose->last_busno); |
Kunihiko Hayashi | 4ebeb4c | 2019-08-23 10:56:55 +0900 | [diff] [blame] | 469 | printf("# %-18s %-18s %-18s %s\n", "Bus start", "Phys start", "Size", |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 470 | "Flags"); |
| 471 | for (i = 0, reg = hose->regions; i < hose->region_count; i++, reg++) { |
Kunihiko Hayashi | 4ebeb4c | 2019-08-23 10:56:55 +0900 | [diff] [blame] | 472 | printf("%d %#018llx %#018llx %#018llx ", i, |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 473 | (unsigned long long)reg->bus_start, |
| 474 | (unsigned long long)reg->phys_start, |
| 475 | (unsigned long long)reg->size); |
| 476 | if (!(reg->flags & PCI_REGION_TYPE)) |
| 477 | printf("mem "); |
| 478 | for (j = 0; j < ARRAY_SIZE(pci_flag_info); j++) { |
| 479 | if (reg->flags & pci_flag_info[j].flag) |
| 480 | printf("%s ", pci_flag_info[j].name); |
| 481 | } |
| 482 | printf("\n"); |
| 483 | } |
| 484 | } |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 485 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 486 | /* PCI Configuration Space access commands |
| 487 | * |
| 488 | * Syntax: |
| 489 | * pci display[.b, .w, .l] bus.device.function} [addr] [len] |
| 490 | * pci next[.b, .w, .l] bus.device.function [addr] |
| 491 | * pci modify[.b, .w, .l] bus.device.function [addr] |
| 492 | * pci write[.b, .w, .l] bus.device.function addr value |
| 493 | */ |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 494 | static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 495 | { |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 496 | ulong addr = 0, value = 0, cmd_size = 0; |
| 497 | enum pci_size_t size = PCI_SIZE_32; |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 498 | struct udevice *dev, *bus; |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 499 | int busnum = -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 500 | pci_dev_t bdf = 0; |
| 501 | char cmd = 's'; |
Simon Glass | bfa4191 | 2015-11-26 19:51:18 -0700 | [diff] [blame] | 502 | int ret = 0; |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 503 | char *endp; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 504 | |
| 505 | if (argc > 1) |
| 506 | cmd = argv[1][0]; |
| 507 | |
| 508 | switch (cmd) { |
| 509 | case 'd': /* display */ |
| 510 | case 'n': /* next */ |
| 511 | case 'm': /* modify */ |
| 512 | case 'w': /* write */ |
| 513 | /* Check for a size specification. */ |
Simon Glass | 72ef5b6 | 2015-11-26 19:51:26 -0700 | [diff] [blame] | 514 | cmd_size = cmd_get_data_size(argv[1], 4); |
| 515 | size = (cmd_size == 4) ? PCI_SIZE_32 : cmd_size - 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 516 | if (argc > 3) |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 517 | addr = hextoul(argv[3], NULL); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 518 | if (argc > 4) |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 519 | value = hextoul(argv[4], NULL); |
Heinrich Schuchardt | 62d92d8 | 2023-04-01 09:43:33 +0200 | [diff] [blame] | 520 | fallthrough; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 521 | case 'h': /* header */ |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 522 | case 'b': /* bars */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 523 | if (argc < 3) |
| 524 | goto usage; |
| 525 | if ((bdf = get_pci_dev(argv[2])) == -1) |
| 526 | return 1; |
| 527 | break; |
John Schmoller | 96d6160 | 2010-10-22 00:20:23 -0500 | [diff] [blame] | 528 | case 'e': |
Stephen Warren | e578b92 | 2016-01-26 11:10:11 -0700 | [diff] [blame] | 529 | pci_init(); |
| 530 | return 0; |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 531 | case 'r': /* no break */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 532 | default: /* scan bus */ |
| 533 | value = 1; /* short listing */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 534 | if (argc > 1) { |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 535 | if (cmd != 'r' && argv[argc-1][0] == 'l') { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 536 | value = 0; |
| 537 | argc--; |
| 538 | } |
Pali Rohár | 3932093 | 2022-01-17 16:38:38 +0100 | [diff] [blame] | 539 | if (argc > 2 || (argc > 1 && cmd != 'r' && argv[1][0] != 's')) { |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 540 | if (argv[argc - 1][0] != '*') { |
| 541 | busnum = hextoul(argv[argc - 1], &endp); |
| 542 | if (*endp) |
| 543 | goto usage; |
| 544 | } |
Pali Rohár | 6850a5a | 2022-01-17 16:38:39 +0100 | [diff] [blame] | 545 | argc--; |
Pali Rohár | 3932093 | 2022-01-17 16:38:38 +0100 | [diff] [blame] | 546 | } |
Pali Rohár | 6850a5a | 2022-01-17 16:38:39 +0100 | [diff] [blame] | 547 | if (cmd == 'r' && argc > 2) |
| 548 | goto usage; |
| 549 | else if (cmd != 'r' && (argc > 2 || (argc == 2 && argv[1][0] != 's'))) |
| 550 | goto usage; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 551 | } |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 552 | if (busnum == -1) { |
| 553 | if (cmd != 'r') { |
| 554 | for (busnum = 0; |
| 555 | uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0; |
| 556 | busnum++) |
| 557 | pciinfo(bus, value, true); |
| 558 | } else { |
| 559 | for (busnum = 0; |
| 560 | uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus) == 0; |
| 561 | busnum++) { |
| 562 | /* Regions are controller specific so skip non-root buses */ |
| 563 | if (device_is_on_pci_bus(bus)) |
| 564 | continue; |
| 565 | pci_show_regions(bus); |
| 566 | } |
| 567 | } |
| 568 | return 0; |
| 569 | } |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 570 | ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, &bus); |
| 571 | if (ret) { |
| 572 | printf("No such bus\n"); |
| 573 | return CMD_RET_FAILURE; |
| 574 | } |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 575 | if (cmd == 'r') |
| 576 | pci_show_regions(bus); |
| 577 | else |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 578 | pciinfo(bus, value, false); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 579 | return 0; |
| 580 | } |
| 581 | |
Simon Glass | f3f1fae | 2015-11-29 13:17:48 -0700 | [diff] [blame] | 582 | ret = dm_pci_bus_find_bdf(bdf, &dev); |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 583 | if (ret) { |
| 584 | printf("No such device\n"); |
| 585 | return CMD_RET_FAILURE; |
| 586 | } |
Simon Glass | 32ec5b3 | 2015-11-26 19:51:27 -0700 | [diff] [blame] | 587 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 588 | switch (argv[1][0]) { |
| 589 | case 'h': /* header */ |
Simon Glass | 32ec5b3 | 2015-11-26 19:51:27 -0700 | [diff] [blame] | 590 | pci_header_show(dev); |
Simon Glass | bfa4191 | 2015-11-26 19:51:18 -0700 | [diff] [blame] | 591 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 592 | case 'd': /* display */ |
Simon Glass | 32ec5b3 | 2015-11-26 19:51:27 -0700 | [diff] [blame] | 593 | return pci_cfg_display(dev, addr, size, value); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 594 | case 'n': /* next */ |
| 595 | if (argc < 4) |
| 596 | goto usage; |
Simon Glass | 32ec5b3 | 2015-11-26 19:51:27 -0700 | [diff] [blame] | 597 | ret = pci_cfg_modify(dev, addr, size, value, 0); |
Simon Glass | bfa4191 | 2015-11-26 19:51:18 -0700 | [diff] [blame] | 598 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 599 | case 'm': /* modify */ |
| 600 | if (argc < 4) |
| 601 | goto usage; |
Simon Glass | 32ec5b3 | 2015-11-26 19:51:27 -0700 | [diff] [blame] | 602 | ret = pci_cfg_modify(dev, addr, size, value, 1); |
Simon Glass | bfa4191 | 2015-11-26 19:51:18 -0700 | [diff] [blame] | 603 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 604 | case 'w': /* write */ |
| 605 | if (argc < 5) |
| 606 | goto usage; |
Simon Glass | cab24b3 | 2015-11-26 19:51:29 -0700 | [diff] [blame] | 607 | ret = dm_pci_write_config(dev, addr, value, size); |
Simon Glass | bfa4191 | 2015-11-26 19:51:18 -0700 | [diff] [blame] | 608 | break; |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 609 | case 'b': /* bars */ |
| 610 | return pci_bar_show(dev); |
Simon Glass | bfa4191 | 2015-11-26 19:51:18 -0700 | [diff] [blame] | 611 | default: |
| 612 | ret = CMD_RET_USAGE; |
| 613 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Simon Glass | bfa4191 | 2015-11-26 19:51:18 -0700 | [diff] [blame] | 616 | return ret; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 617 | usage: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 618 | return CMD_RET_USAGE; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 619 | } |
| 620 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 621 | /***************************************************/ |
| 622 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 623 | #ifdef CONFIG_SYS_LONGHELP |
| 624 | static char pci_help_text[] = |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 625 | "[bus|*] [long]\n" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 626 | " - short or long list of PCI devices on bus 'bus'\n" |
John Schmoller | 96d6160 | 2010-10-22 00:20:23 -0500 | [diff] [blame] | 627 | "pci enum\n" |
Stephen Warren | e578b92 | 2016-01-26 11:10:11 -0700 | [diff] [blame] | 628 | " - Enumerate PCI buses\n" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 629 | "pci header b.d.f\n" |
| 630 | " - show header of PCI device 'bus.device.function'\n" |
Yehuda Yitschak | e5f96a8 | 2016-12-01 17:14:18 +0200 | [diff] [blame] | 631 | "pci bar b.d.f\n" |
| 632 | " - show BARs base and size for device b.d.f'\n" |
Pali Rohár | 1a4942f | 2022-01-17 16:38:40 +0100 | [diff] [blame] | 633 | "pci regions [bus|*]\n" |
Simon Glass | b997a73 | 2017-04-08 13:10:06 -0600 | [diff] [blame] | 634 | " - show PCI regions\n" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 635 | "pci display[.b, .w, .l] b.d.f [address] [# of objects]\n" |
| 636 | " - display PCI configuration space (CFG)\n" |
| 637 | "pci next[.b, .w, .l] b.d.f address\n" |
| 638 | " - modify, read and keep CFG address\n" |
| 639 | "pci modify[.b, .w, .l] b.d.f address\n" |
| 640 | " - modify, auto increment CFG address\n" |
| 641 | "pci write[.b, .w, .l] b.d.f address value\n" |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 642 | " - write to CFG address"; |
| 643 | #endif |
| 644 | |
| 645 | U_BOOT_CMD( |
| 646 | pci, 5, 1, do_pci, |
| 647 | "list and access PCI Configuration Space", pci_help_text |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 648 | ); |