2 * $Id: pcibios.c,v 1.1 2001/08/24 12:38:19 dwmw2 Exp $
4 * arch/sh/kernel/pcibios.c
8 * Provided here are generic versions of:
9 * pcibios_update_resource()
10 * pcibios_align_resource()
11 * pcibios_enable_device()
12 * pcibios_set_master()
13 * pcibios_update_irq()
15 * These functions are collected here to reduce duplication of common
16 * code amongst the many platform-specific PCI support code files.
18 * Platform-specific files are expected to provide:
22 * pcibios_fixup_pbus_ranges()
25 #include <linux/kernel.h>
26 #include <linux/pci.h>
27 #include <linux/init.h>
30 pcibios_update_resource(struct pci_dev *dev, struct resource *root,
31 struct resource *res, int resource)
36 new = res->start | (res->flags & PCI_REGION_FLAG_MASK);
38 reg = PCI_BASE_ADDRESS_0 + 4*resource;
39 } else if (resource == PCI_ROM_RESOURCE) {
40 res->flags |= PCI_ROM_ADDRESS_ENABLE;
41 new |= PCI_ROM_ADDRESS_ENABLE;
42 reg = dev->rom_base_reg;
44 /* Somebody might have asked allocation of a non-standard resource */
48 pci_write_config_dword(dev, reg, new);
49 pci_read_config_dword(dev, reg, &check);
50 if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) {
51 printk(KERN_ERR "PCI: Error while updating region "
52 "%s/%d (%08x != %08x)\n", dev->slot_name, resource,
58 * We need to avoid collisions with `mirrored' VGA ports
59 * and other strange ISA hardware, so we always want the
60 * addresses to be allocated in the 0x000-0x0ff region
63 void pcibios_align_resource(void *data, struct resource *res,
64 unsigned long size, unsigned long align)
66 if (res->flags & IORESOURCE_IO) {
67 unsigned long start = res->start;
70 start = (start + 0x3ff) & ~0x3ff;
76 int pcibios_enable_device(struct pci_dev *dev, int mask)
82 pci_read_config_word(dev, PCI_COMMAND, &cmd);
84 for(idx=0; idx<6; idx++) {
85 if (!(mask & (1 << idx)))
87 r = &dev->resource[idx];
88 if (!r->start && r->end) {
89 printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", dev->slot_name);
92 if (r->flags & IORESOURCE_IO)
93 cmd |= PCI_COMMAND_IO;
94 if (r->flags & IORESOURCE_MEM)
95 cmd |= PCI_COMMAND_MEMORY;
97 if (dev->resource[PCI_ROM_RESOURCE].start)
98 cmd |= PCI_COMMAND_MEMORY;
100 printk(KERN_INFO "PCI: Enabling device %s (%04x -> %04x)\n", dev->name, old_cmd, cmd);
101 pci_write_config_word(dev, PCI_COMMAND, cmd);
107 * If we set up a device for bus mastering, we need to check and set
108 * the latency timer as it may not be properly set.
110 unsigned int pcibios_max_latency = 255;
112 void pcibios_set_master(struct pci_dev *dev)
115 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
117 lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
118 else if (lat > pcibios_max_latency)
119 lat = pcibios_max_latency;
122 printk(KERN_INFO "PCI: Setting latency timer of device %s to %d\n", dev->name, lat);
123 pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
126 void __init pcibios_update_irq(struct pci_dev *dev, int irq)
128 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);