2 * $Id: pcibios.c,v 1.1 2001/08/24 12:38:19 dwmw2 Exp $
4 * arch/sh/kernel/pcibios.c
6 * Copyright (C) 2002 STMicroelectronics Limited
7 * Author : David J. McKay
9 * Copyright (C) 2004 Richard Curnow, SuperH UK Limited
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
16 * Provided here are generic versions of:
17 * pcibios_update_resource()
18 * pcibios_align_resource()
19 * pcibios_enable_device()
20 * pcibios_set_master()
21 * pcibios_update_irq()
23 * These functions are collected here to reduce duplication of common
24 * code amongst the many platform-specific PCI support code files.
26 * Platform-specific files are expected to provide:
30 * pcibios_fixup_pbus_ranges()
33 #include <linux/kernel.h>
34 #include <linux/pci.h>
35 #include <linux/init.h>
38 pcibios_update_resource(struct pci_dev *dev, struct resource *root,
39 struct resource *res, int resource)
44 new = res->start | (res->flags & PCI_REGION_FLAG_MASK);
46 reg = PCI_BASE_ADDRESS_0 + 4*resource;
47 } else if (resource == PCI_ROM_RESOURCE) {
48 res->flags |= IORESOURCE_ROM_ENABLE;
49 new |= PCI_ROM_ADDRESS_ENABLE;
50 reg = dev->rom_base_reg;
52 /* Somebody might have asked allocation of a non-standard resource */
56 pci_write_config_dword(dev, reg, new);
57 pci_read_config_dword(dev, reg, &check);
58 if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) {
59 printk(KERN_ERR "PCI: Error while updating region "
60 "%s/%d (%08x != %08x)\n", pci_name(dev), resource,
66 * We need to avoid collisions with `mirrored' VGA ports
67 * and other strange ISA hardware, so we always want the
68 * addresses to be allocated in the 0x000-0x0ff region
71 void pcibios_align_resource(void *data, struct resource *res,
72 resource_size_t size, resource_size_t align)
74 if (res->flags & IORESOURCE_IO) {
75 resource_size_t start = res->start;
78 start = (start + 0x3ff) & ~0x3ff;
84 static void pcibios_enable_bridge(struct pci_dev *dev)
86 struct pci_bus *bus = dev->subordinate;
89 pci_read_config_word(dev, PCI_COMMAND, &cmd);
92 if (bus->resource[0]->flags & IORESOURCE_IO) {
93 cmd |= PCI_COMMAND_IO;
95 if ((bus->resource[1]->flags & IORESOURCE_MEM) ||
96 (bus->resource[2]->flags & IORESOURCE_PREFETCH)) {
97 cmd |= PCI_COMMAND_MEMORY;
100 if (cmd != old_cmd) {
101 pci_write_config_word(dev, PCI_COMMAND, cmd);
104 printk("PCI bridge %s, command register -> %04x\n",
111 int pcibios_enable_device(struct pci_dev *dev, int mask)
117 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
118 pcibios_enable_bridge(dev);
121 pci_read_config_word(dev, PCI_COMMAND, &cmd);
123 for(idx=0; idx<6; idx++) {
124 if (!(mask & (1 << idx)))
126 r = &dev->resource[idx];
127 if (!r->start && r->end) {
128 printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
131 if (r->flags & IORESOURCE_IO)
132 cmd |= PCI_COMMAND_IO;
133 if (r->flags & IORESOURCE_MEM)
134 cmd |= PCI_COMMAND_MEMORY;
136 if (dev->resource[PCI_ROM_RESOURCE].start)
137 cmd |= PCI_COMMAND_MEMORY;
138 if (cmd != old_cmd) {
139 printk(KERN_INFO "PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
140 pci_write_config_word(dev, PCI_COMMAND, cmd);
146 * If we set up a device for bus mastering, we need to check and set
147 * the latency timer as it may not be properly set.
149 unsigned int pcibios_max_latency = 255;
151 void pcibios_set_master(struct pci_dev *dev)
154 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
156 lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
157 else if (lat > pcibios_max_latency)
158 lat = pcibios_max_latency;
161 printk(KERN_INFO "PCI: Setting latency timer of device %s to %d\n", pci_name(dev), lat);
162 pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
165 void __init pcibios_update_irq(struct pci_dev *dev, int irq)
167 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);