Skip to content

Commit dc4e6f2

Browse files
puranjaymohanbjorn-helgaas
authored andcommitted
PCI: Use resource names in PCI log messages
Use the pci_resource_name() to get the name of the resource and use it while printing log messages. [bhelgaas: rename to match struct resource * names, also use names in other BAR messages] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Puranjay Mohan <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 65f8e0b commit dc4e6f2

File tree

6 files changed

+103
-72
lines changed

6 files changed

+103
-72
lines changed

drivers/pci/iov.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
745745
u16 ctrl, total;
746746
struct pci_sriov *iov;
747747
struct resource *res;
748+
const char *res_name;
748749
struct pci_dev *pdev;
749750

750751
pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &ctrl);
@@ -785,6 +786,8 @@ static int sriov_init(struct pci_dev *dev, int pos)
785786
nres = 0;
786787
for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) {
787788
res = &dev->resource[i + PCI_IOV_RESOURCES];
789+
res_name = pci_resource_name(dev, i + PCI_IOV_RESOURCES);
790+
788791
/*
789792
* If it is already FIXED, don't change it, something
790793
* (perhaps EA or header fixups) wants it this way.
@@ -802,8 +805,8 @@ static int sriov_init(struct pci_dev *dev, int pos)
802805
}
803806
iov->barsz[i] = resource_size(res);
804807
res->end = res->start + resource_size(res) * total - 1;
805-
pci_info(dev, "VF(n) BAR%d space: %pR (contains BAR%d for %d VFs)\n",
806-
i, res, i, total);
808+
pci_info(dev, "%s %pR: contains BAR %d for %d VFs\n",
809+
res_name, res, i, total);
807810
i += bar64;
808811
nres++;
809812
}

drivers/pci/pci.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,6 +3350,7 @@ static struct resource *pci_ea_get_resource(struct pci_dev *dev, u8 bei,
33503350
static int pci_ea_read(struct pci_dev *dev, int offset)
33513351
{
33523352
struct resource *res;
3353+
const char *res_name;
33533354
int ent_size, ent_offset = offset;
33543355
resource_size_t start, end;
33553356
unsigned long flags;
@@ -3379,6 +3380,7 @@ static int pci_ea_read(struct pci_dev *dev, int offset)
33793380
goto out;
33803381

33813382
res = pci_ea_get_resource(dev, bei, prop);
3383+
res_name = pci_resource_name(dev, bei);
33823384
if (!res) {
33833385
pci_err(dev, "Unsupported EA entry BEI: %u\n", bei);
33843386
goto out;
@@ -3452,16 +3454,16 @@ static int pci_ea_read(struct pci_dev *dev, int offset)
34523454
res->flags = flags;
34533455

34543456
if (bei <= PCI_EA_BEI_BAR5)
3455-
pci_info(dev, "BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
3456-
bei, res, prop);
3457+
pci_info(dev, "%s %pR: from Enhanced Allocation, properties %#02x\n",
3458+
res_name, res, prop);
34573459
else if (bei == PCI_EA_BEI_ROM)
3458-
pci_info(dev, "ROM: %pR (from Enhanced Allocation, properties %#02x)\n",
3459-
res, prop);
3460+
pci_info(dev, "%s %pR: from Enhanced Allocation, properties %#02x\n",
3461+
res_name, res, prop);
34603462
else if (bei >= PCI_EA_BEI_VF_BAR0 && bei <= PCI_EA_BEI_VF_BAR5)
3461-
pci_info(dev, "VF BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
3462-
bei - PCI_EA_BEI_VF_BAR0, res, prop);
3463+
pci_info(dev, "%s %pR: from Enhanced Allocation, properties %#02x\n",
3464+
res_name, res, prop);
34633465
else
3464-
pci_info(dev, "BEI %d res: %pR (from Enhanced Allocation, properties %#02x)\n",
3466+
pci_info(dev, "BEI %d %pR: from Enhanced Allocation, properties %#02x\n",
34653467
bei, res, prop);
34663468

34673469
out:
@@ -6749,14 +6751,15 @@ static void pci_request_resource_alignment(struct pci_dev *dev, int bar,
67496751
resource_size_t align, bool resize)
67506752
{
67516753
struct resource *r = &dev->resource[bar];
6754+
const char *r_name = pci_resource_name(dev, bar);
67526755
resource_size_t size;
67536756

67546757
if (!(r->flags & IORESOURCE_MEM))
67556758
return;
67566759

67576760
if (r->flags & IORESOURCE_PCI_FIXED) {
6758-
pci_info(dev, "BAR%d %pR: ignoring requested alignment %#llx\n",
6759-
bar, r, (unsigned long long)align);
6761+
pci_info(dev, "%s %pR: ignoring requested alignment %#llx\n",
6762+
r_name, r, (unsigned long long)align);
67606763
return;
67616764
}
67626765

@@ -6792,8 +6795,8 @@ static void pci_request_resource_alignment(struct pci_dev *dev, int bar,
67926795
* devices and we use the second.
67936796
*/
67946797

6795-
pci_info(dev, "BAR%d %pR: requesting alignment to %#llx\n",
6796-
bar, r, (unsigned long long)align);
6798+
pci_info(dev, "%s %pR: requesting alignment to %#llx\n",
6799+
r_name, r, (unsigned long long)align);
67976800

67986801
if (resize) {
67996802
r->start = 0;

drivers/pci/probe.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
180180
u64 l64, sz64, mask64;
181181
u16 orig_cmd;
182182
struct pci_bus_region region, inverted_region;
183+
const char *res_name = pci_resource_name(dev, res - dev->resource);
183184

184185
mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
185186

@@ -254,8 +255,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
254255

255256
sz64 = pci_size(l64, sz64, mask64);
256257
if (!sz64) {
257-
pci_info(dev, FW_BUG "reg 0x%x: invalid BAR (can't size)\n",
258-
pos);
258+
pci_info(dev, FW_BUG "%s: invalid; can't size\n", res_name);
259259
goto fail;
260260
}
261261

@@ -265,8 +265,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
265265
res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
266266
res->start = 0;
267267
res->end = 0;
268-
pci_err(dev, "reg 0x%x: can't handle BAR larger than 4GB (size %#010llx)\n",
269-
pos, (unsigned long long)sz64);
268+
pci_err(dev, "%s: can't handle BAR larger than 4GB (size %#010llx)\n",
269+
res_name, (unsigned long long)sz64);
270270
goto out;
271271
}
272272

@@ -275,8 +275,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
275275
res->flags |= IORESOURCE_UNSET;
276276
res->start = 0;
277277
res->end = sz64 - 1;
278-
pci_info(dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n",
279-
pos, (unsigned long long)l64);
278+
pci_info(dev, "%s: can't handle BAR above 4GB (bus address %#010llx)\n",
279+
res_name, (unsigned long long)l64);
280280
goto out;
281281
}
282282
}
@@ -302,8 +302,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
302302
res->flags |= IORESOURCE_UNSET;
303303
res->start = 0;
304304
res->end = region.end - region.start;
305-
pci_info(dev, "reg 0x%x: initial BAR value %#010llx invalid\n",
306-
pos, (unsigned long long)region.start);
305+
pci_info(dev, "%s: initial BAR value %#010llx invalid\n",
306+
res_name, (unsigned long long)region.start);
307307
}
308308

309309
goto out;
@@ -313,7 +313,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
313313
res->flags = 0;
314314
out:
315315
if (res->flags)
316-
pci_info(dev, "reg 0x%x: %pR\n", pos, res);
316+
pci_info(dev, "%s %pR\n", res_name, res);
317317

318318
return (res->flags & IORESOURCE_MEM_64) ? 1 : 0;
319319
}
@@ -1967,14 +1967,14 @@ int pci_setup_device(struct pci_dev *dev)
19671967
res = &dev->resource[0];
19681968
res->flags = LEGACY_IO_RESOURCE;
19691969
pcibios_bus_to_resource(dev->bus, res, &region);
1970-
pci_info(dev, "legacy IDE quirk: reg 0x10: %pR\n",
1970+
pci_info(dev, "BAR 0 %pR: legacy IDE quirk\n",
19711971
res);
19721972
region.start = 0x3F6;
19731973
region.end = 0x3F6;
19741974
res = &dev->resource[1];
19751975
res->flags = LEGACY_IO_RESOURCE;
19761976
pcibios_bus_to_resource(dev->bus, res, &region);
1977-
pci_info(dev, "legacy IDE quirk: reg 0x14: %pR\n",
1977+
pci_info(dev, "BAR 1 %pR: legacy IDE quirk\n",
19781978
res);
19791979
}
19801980
if ((progif & 4) == 0) {
@@ -1983,14 +1983,14 @@ int pci_setup_device(struct pci_dev *dev)
19831983
res = &dev->resource[2];
19841984
res->flags = LEGACY_IO_RESOURCE;
19851985
pcibios_bus_to_resource(dev->bus, res, &region);
1986-
pci_info(dev, "legacy IDE quirk: reg 0x18: %pR\n",
1986+
pci_info(dev, "BAR 2 %pR: legacy IDE quirk\n",
19871987
res);
19881988
region.start = 0x376;
19891989
region.end = 0x376;
19901990
res = &dev->resource[3];
19911991
res->flags = LEGACY_IO_RESOURCE;
19921992
pcibios_bus_to_resource(dev->bus, res, &region);
1993-
pci_info(dev, "legacy IDE quirk: reg 0x1c: %pR\n",
1993+
pci_info(dev, "BAR 3 %pR: legacy IDE quirk\n",
19941994
res);
19951995
}
19961996
}

drivers/pci/quirks.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,14 @@ static void quirk_extend_bar_to_page(struct pci_dev *dev)
570570

571571
for (i = 0; i < PCI_STD_NUM_BARS; i++) {
572572
struct resource *r = &dev->resource[i];
573+
const char *r_name = pci_resource_name(dev, i);
573574

574575
if (r->flags & IORESOURCE_MEM && resource_size(r) < PAGE_SIZE) {
575576
r->end = PAGE_SIZE - 1;
576577
r->start = 0;
577578
r->flags |= IORESOURCE_UNSET;
578-
pci_info(dev, "expanded BAR %d to page size: %pR\n",
579-
i, r);
579+
pci_info(dev, "%s %pR: expanded to page size\n",
580+
r_name, r);
580581
}
581582
}
582583
}
@@ -605,6 +606,7 @@ static void quirk_io(struct pci_dev *dev, int pos, unsigned int size,
605606
u32 region;
606607
struct pci_bus_region bus_region;
607608
struct resource *res = dev->resource + pos;
609+
const char *res_name = pci_resource_name(dev, pos);
608610

609611
pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + (pos << 2), &region);
610612

@@ -622,8 +624,7 @@ static void quirk_io(struct pci_dev *dev, int pos, unsigned int size,
622624
bus_region.end = region + size - 1;
623625
pcibios_bus_to_resource(dev->bus, res, &bus_region);
624626

625-
pci_info(dev, FW_BUG "%s quirk: reg 0x%x: %pR\n",
626-
name, PCI_BASE_ADDRESS_0 + (pos << 2), res);
627+
pci_info(dev, FW_BUG "%s %pR: %s quirk\n", res_name, res, name);
627628
}
628629

629630
/*
@@ -670,6 +671,12 @@ static void quirk_io_region(struct pci_dev *dev, int port,
670671
bus_region.end = region + size - 1;
671672
pcibios_bus_to_resource(dev->bus, res, &bus_region);
672673

674+
/*
675+
* "res" is typically a bridge window resource that's not being
676+
* used for a bridge window, so it's just a place to stash this
677+
* non-standard resource. Printing "nr" or pci_resource_name() of
678+
* it doesn't really make sense.
679+
*/
673680
if (!pci_claim_resource(dev, nr))
674681
pci_info(dev, "quirk: %pR claimed by %s\n", res, name);
675682
}

drivers/pci/setup-bus.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
213213
struct list_head *head)
214214
{
215215
struct resource *res;
216+
const char *res_name;
216217
struct pci_dev_resource *add_res, *tmp;
217218
struct pci_dev_resource *dev_res;
218219
resource_size_t add_size, align;
@@ -222,6 +223,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
222223
bool found_match = false;
223224

224225
res = add_res->res;
226+
225227
/* Skip resource that has been reset */
226228
if (!res->flags)
227229
goto out;
@@ -237,6 +239,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
237239
continue;
238240

239241
idx = res - &add_res->dev->resource[0];
242+
res_name = pci_resource_name(add_res->dev, idx);
240243
add_size = add_res->add_size;
241244
align = add_res->min_align;
242245
if (!resource_size(res)) {
@@ -249,9 +252,9 @@ static void reassign_resources_sorted(struct list_head *realloc_head,
249252
(IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN);
250253
if (pci_reassign_resource(add_res->dev, idx,
251254
add_size, align))
252-
pci_info(add_res->dev, "failed to add %llx res[%d]=%pR\n",
253-
(unsigned long long) add_size, idx,
254-
res);
255+
pci_info(add_res->dev, "%s %pR: failed to add %llx\n",
256+
res_name, res,
257+
(unsigned long long) add_size);
255258
}
256259
out:
257260
list_del(&add_res->list);
@@ -571,6 +574,7 @@ EXPORT_SYMBOL(pci_setup_cardbus);
571574
static void pci_setup_bridge_io(struct pci_dev *bridge)
572575
{
573576
struct resource *res;
577+
const char *res_name;
574578
struct pci_bus_region region;
575579
unsigned long io_mask;
576580
u8 io_base_lo, io_limit_lo;
@@ -583,6 +587,7 @@ static void pci_setup_bridge_io(struct pci_dev *bridge)
583587

584588
/* Set up the top and bottom of the PCI I/O segment for this bus */
585589
res = &bridge->resource[PCI_BRIDGE_IO_WINDOW];
590+
res_name = pci_resource_name(bridge, PCI_BRIDGE_IO_WINDOW);
586591
pcibios_resource_to_bus(bridge->bus, &region, res);
587592
if (res->flags & IORESOURCE_IO) {
588593
pci_read_config_word(bridge, PCI_IO_BASE, &l);
@@ -591,7 +596,7 @@ static void pci_setup_bridge_io(struct pci_dev *bridge)
591596
l = ((u16) io_limit_lo << 8) | io_base_lo;
592597
/* Set up upper 16 bits of I/O base/limit */
593598
io_upper16 = (region.end & 0xffff0000) | (region.start >> 16);
594-
pci_info(bridge, " bridge window %pR\n", res);
599+
pci_info(bridge, " %s %pR\n", res_name, res);
595600
} else {
596601
/* Clear upper 16 bits of I/O base/limit */
597602
io_upper16 = 0;
@@ -608,16 +613,18 @@ static void pci_setup_bridge_io(struct pci_dev *bridge)
608613
static void pci_setup_bridge_mmio(struct pci_dev *bridge)
609614
{
610615
struct resource *res;
616+
const char *res_name;
611617
struct pci_bus_region region;
612618
u32 l;
613619

614620
/* Set up the top and bottom of the PCI Memory segment for this bus */
615621
res = &bridge->resource[PCI_BRIDGE_MEM_WINDOW];
622+
res_name = pci_resource_name(bridge, PCI_BRIDGE_MEM_WINDOW);
616623
pcibios_resource_to_bus(bridge->bus, &region, res);
617624
if (res->flags & IORESOURCE_MEM) {
618625
l = (region.start >> 16) & 0xfff0;
619626
l |= region.end & 0xfff00000;
620-
pci_info(bridge, " bridge window %pR\n", res);
627+
pci_info(bridge, " %s %pR\n", res_name, res);
621628
} else {
622629
l = 0x0000fff0;
623630
}
@@ -627,6 +634,7 @@ static void pci_setup_bridge_mmio(struct pci_dev *bridge)
627634
static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge)
628635
{
629636
struct resource *res;
637+
const char *res_name;
630638
struct pci_bus_region region;
631639
u32 l, bu, lu;
632640

@@ -640,6 +648,7 @@ static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge)
640648
/* Set up PREF base/limit */
641649
bu = lu = 0;
642650
res = &bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
651+
res_name = pci_resource_name(bridge, PCI_BRIDGE_PREF_MEM_WINDOW);
643652
pcibios_resource_to_bus(bridge->bus, &region, res);
644653
if (res->flags & IORESOURCE_PREFETCH) {
645654
l = (region.start >> 16) & 0xfff0;
@@ -648,7 +657,7 @@ static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge)
648657
bu = upper_32_bits(region.start);
649658
lu = upper_32_bits(region.end);
650659
}
651-
pci_info(bridge, " bridge window %pR\n", res);
660+
pci_info(bridge, " %s %pR\n", res_name, res);
652661
} else {
653662
l = 0x0000fff0;
654663
}
@@ -1013,6 +1022,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
10131022
int i;
10141023

10151024
pci_dev_for_each_resource(dev, r, i) {
1025+
const char *r_name = pci_resource_name(dev, i);
10161026
resource_size_t r_size;
10171027

10181028
if (r->parent || (r->flags & IORESOURCE_PCI_FIXED) ||
@@ -1043,8 +1053,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
10431053
if (order < 0)
10441054
order = 0;
10451055
if (order >= ARRAY_SIZE(aligns)) {
1046-
pci_warn(dev, "disabling BAR %d: %pR (bad alignment %#llx)\n",
1047-
i, r, (unsigned long long) align);
1056+
pci_warn(dev, "%s %pR: disabling; bad alignment %#llx\n",
1057+
r_name, r, (unsigned long long) align);
10481058
r->flags = 0;
10491059
continue;
10501060
}
@@ -2235,6 +2245,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
22352245
for (i = PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCE_END;
22362246
i++) {
22372247
struct resource *res = &bridge->resource[i];
2248+
const char *res_name = pci_resource_name(bridge, i);
22382249

22392250
if ((res->flags ^ type) & PCI_RES_TYPE_MASK)
22402251
continue;
@@ -2247,8 +2258,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
22472258
if (ret)
22482259
goto cleanup;
22492260

2250-
pci_info(bridge, "BAR %d: releasing %pR\n",
2251-
i, res);
2261+
pci_info(bridge, "%s %pR: releasing\n", res_name, res);
22522262

22532263
if (res->parent)
22542264
release_resource(res);

0 commit comments

Comments
 (0)