Skip to content

Commit 842de40

Browse files
Bjorn Helgaasgregkh
Bjorn Helgaas
authored andcommitted
PCI: add generic pci_enable_resources()
Each architecture has its own pcibios_enable_resources() implementation. These differ in many minor ways that have nothing to do with actual architectural differences. Follow-on patches will make most arches use this generic version instead. This version is based on powerpc, which seemed most up-to-date. The only functional difference from the x86 version is that this uses "!r->parent" to check for resource collisions instead of "!r->start && r->end". Signed-off-by: Bjorn Helgaas <[email protected]> Acked-by: Benjamin Herrenschmidt <[email protected]> Acked-by: David Howells <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7d715a6 commit 842de40

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

drivers/pci/setup-res.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,46 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
263263
}
264264
}
265265
}
266+
267+
int pci_enable_resources(struct pci_dev *dev, int mask)
268+
{
269+
u16 cmd, old_cmd;
270+
int i;
271+
struct resource *r;
272+
273+
pci_read_config_word(dev, PCI_COMMAND, &cmd);
274+
old_cmd = cmd;
275+
276+
for (i = 0; i < PCI_NUM_RESOURCES; i++) {
277+
if (!(mask & (1 << i)))
278+
continue;
279+
280+
r = &dev->resource[i];
281+
282+
if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
283+
continue;
284+
if ((i == PCI_ROM_RESOURCE) &&
285+
(!(r->flags & IORESOURCE_ROM_ENABLE)))
286+
continue;
287+
288+
if (!r->parent) {
289+
dev_err(&dev->dev, "device not available because of "
290+
"BAR %d [%llx:%llx] collisions\n", i,
291+
(unsigned long long) r->start,
292+
(unsigned long long) r->end);
293+
return -EINVAL;
294+
}
295+
296+
if (r->flags & IORESOURCE_IO)
297+
cmd |= PCI_COMMAND_IO;
298+
if (r->flags & IORESOURCE_MEM)
299+
cmd |= PCI_COMMAND_MEMORY;
300+
}
301+
302+
if (cmd != old_cmd) {
303+
dev_info(&dev->dev, "enabling device (%04x -> %04x)\n",
304+
old_cmd, cmd);
305+
pci_write_config_word(dev, PCI_COMMAND, cmd);
306+
}
307+
return 0;
308+
}

include/linux/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ int pci_claim_resource(struct pci_dev *, int);
624624
void pci_assign_unassigned_resources(void);
625625
void pdev_enable_device(struct pci_dev *);
626626
void pdev_sort_resources(struct pci_dev *, struct resource_list *);
627+
int pci_enable_resources(struct pci_dev *, int mask);
627628
void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
628629
int (*)(struct pci_dev *, u8, u8));
629630
#define HAVE_PCI_REQ_REGIONS 2

0 commit comments

Comments
 (0)