Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / cris / arch-v32 / drivers / pci / bios.c
blob6b9e6cfaa29e59ad31d19abdae1c598603be4b7e
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/pci.h>
3 #include <linux/kernel.h>
4 #include <hwregs/intr_vect.h>
6 void pcibios_set_master(struct pci_dev *dev)
8 u8 lat;
9 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
10 printk(KERN_DEBUG "PCI: Setting latency timer of device %s to %d\n", pci_name(dev), lat);
11 pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
14 resource_size_t
15 pcibios_align_resource(void *data, const struct resource *res,
16 resource_size_t size, resource_size_t align)
18 resource_size_t start = res->start;
20 if ((res->flags & IORESOURCE_IO) && (start & 0x300))
21 start = (start + 0x3ff) & ~0x3ff;
23 return start;
26 int pcibios_enable_resources(struct pci_dev *dev, int mask)
28 u16 cmd, old_cmd;
29 int idx;
30 struct resource *r;
32 pci_read_config_word(dev, PCI_COMMAND, &cmd);
33 old_cmd = cmd;
34 for(idx=0; idx<6; idx++) {
35 /* Only set up the requested stuff */
36 if (!(mask & (1<<idx)))
37 continue;
39 r = &dev->resource[idx];
40 if (!r->start && r->end) {
41 printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
42 return -EINVAL;
44 if (r->flags & IORESOURCE_IO)
45 cmd |= PCI_COMMAND_IO;
46 if (r->flags & IORESOURCE_MEM)
47 cmd |= PCI_COMMAND_MEMORY;
49 if (dev->resource[PCI_ROM_RESOURCE].start)
50 cmd |= PCI_COMMAND_MEMORY;
51 if (cmd != old_cmd) {
52 printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
53 pci_write_config_word(dev, PCI_COMMAND, cmd);
55 return 0;
58 int pcibios_enable_irq(struct pci_dev *dev)
60 dev->irq = EXT_INTR_VECT;
61 return 0;
64 int pcibios_enable_device(struct pci_dev *dev, int mask)
66 int err;
68 if ((err = pcibios_enable_resources(dev, mask)) < 0)
69 return err;
71 if (!dev->msi_enabled)
72 pcibios_enable_irq(dev);
73 return 0;