2 * linux/arch/alpha/kernel/pci.c
4 * Extruded from code written by
5 * Dave Rusling (david.rusling@reo.mts.dec.com)
6 * David Mosberger (davidm@cs.arizona.edu)
9 /* 2.3.x PCI/resources, 1999 Andrea Arcangeli <andrea@suse.de> */
11 #include <linux/string.h>
12 #include <linux/pci.h>
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/kernel.h>
16 #include <linux/bootmem.h>
17 #include <asm/machvec.h>
24 * Some string constants used by the various core logics.
27 const char *const pci_io_names
[] = {
28 "PCI IO bus 0", "PCI IO bus 1", "PCI IO bus 2", "PCI IO bus 3"
31 const char *const pci_mem_names
[] = {
32 "PCI mem bus 0", "PCI mem bus 1", "PCI mem bus 2", "PCI mem bus 3"
35 const char pci_hae0_name
[] = "HAE0";
39 * The PCI controler list.
42 struct pci_controler
*hose_head
, **hose_tail
= &hose_head
;
49 quirk_eisa_bridge(struct pci_dev
*dev
)
51 dev
->class = PCI_CLASS_BRIDGE_EISA
;
55 quirk_isa_bridge(struct pci_dev
*dev
)
57 dev
->class = PCI_CLASS_BRIDGE_ISA
;
61 quirk_vga_enable_rom(struct pci_dev
*dev
)
63 /* If it's a VGA, enable its BIOS ROM at C0000.
64 But if its a Cirrus 543x/544x DISABLE it, since
65 enabling ROM disables the memory... */
66 if ((dev
->class >> 8) == PCI_CLASS_DISPLAY_VGA
&&
67 /* But if its a Cirrus 543x/544x DISABLE it */
68 (dev
->vendor
!= PCI_VENDOR_ID_CIRRUS
||
69 (dev
->device
< 0x00a0) || (dev
->device
> 0x00ac)))
73 pci_read_config_dword(dev
, dev
->rom_base_reg
, ®
);
74 reg
|= PCI_ROM_ADDRESS_ENABLE
;
75 pci_write_config_dword(dev
, dev
->rom_base_reg
, reg
);
76 dev
->resource
[PCI_ROM_RESOURCE
].flags
|= PCI_ROM_ADDRESS_ENABLE
;
80 struct pci_fixup pcibios_fixups
[] __initdata
= {
81 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82375
,
83 { PCI_FIXUP_HEADER
, PCI_VENDOR_ID_INTEL
, PCI_DEVICE_ID_INTEL_82378
,
85 { PCI_FIXUP_FINAL
, PCI_ANY_ID
, PCI_ANY_ID
, quirk_vga_enable_rom
},
89 #define MAX(val1, val2) ((val1) > (val2) ? (val1) : (val2))
90 #define ALIGN(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
96 pcibios_align_resource(void *data
, struct resource
*res
, unsigned long size
)
98 struct pci_dev
* dev
= data
;
99 unsigned long alignto
;
100 unsigned long start
= res
->start
;
102 if (res
->flags
& IORESOURCE_IO
) {
104 * Aligning to 0x800 rather than the minimum base of
105 * 0x400 is an attempt to avoid having devices in
106 * any 0x?C?? range, which is where the de4x5 driver
107 * probes for EISA cards.
109 * Adaptecs, especially, resent such intrusions.
111 alignto
= MAX(0x800, size
);
112 start
= ALIGN(start
, alignto
);
114 else if (res
->flags
& IORESOURCE_MEM
) {
116 * The following holds at least for the Low Cost
117 * Alpha implementation of the PCI interface:
119 * In sparse memory address space, the first
120 * octant (16MB) of every 128MB segment is
121 * aliased to the very first 16 MB of the
122 * address space (i.e., it aliases the ISA
123 * memory address space). Thus, we try to
124 * avoid allocating PCI devices in that range.
125 * Can be allocated in 2nd-7th octant only.
126 * Devices that need more than 112MB of
127 * address space must be accessed through
128 * dense memory space only!
131 /* Align to multiple of size of minimum base. */
132 alignto
= MAX(0x1000, size
);
133 start
= ALIGN(start
, alignto
);
134 if (size
> 7 * 16*MB
) {
135 printk(KERN_WARNING
"PCI: dev %s "
136 "requests %ld bytes of contiguous "
137 "address space---don't use sparse "
138 "memory accesses on this device!\n",
141 if (((start
/ (16*MB
)) & 0x7) == 0) {
142 start
&= ~(128*MB
- 1);
144 start
= ALIGN(start
, alignto
);
146 if (start
/(128*MB
) != (start
+ size
)/(128*MB
)) {
147 start
&= ~(128*MB
- 1);
148 start
+= (128 + 16)*MB
;
149 start
= ALIGN(start
, alignto
);
163 * Pre-layout host-independant device initialization.
167 pcibios_assign_special(struct pci_dev
* dev
)
171 /* The first three resources of an IDE controler are often magic,
172 so leave them unchanged. This is true, for instance, of the
173 Contaq 82C693 as seen on SX164 and DP264. */
175 if (dev
->class >> 8 == PCI_CLASS_STORAGE_IDE
) {
176 /* Resource 1 of IDE controller is the address of HD_CMD
177 register which actually occupies a single byte (0x3f6
178 for ide0) in reported 0x3f4-3f7 range. We have to fix
179 that to avoid resource conflict with AT-style floppy
181 dev
->resource
[1].start
+= 2;
182 dev
->resource
[1].end
= dev
->resource
[1].start
;
183 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++)
184 if (dev
->resource
[i
].flags
&& dev
->resource
[i
].start
)
185 pci_claim_resource(dev
, i
);
188 * We don't have code that will init the CYPRESS bridge correctly
189 * so we do the next best thing, and depend on the previous
190 * console code to do the right thing, and ignore it here... :-\
192 else if (dev
->vendor
== PCI_VENDOR_ID_CONTAQ
&&
193 dev
->device
== PCI_DEVICE_ID_CONTAQ_82C693
)
194 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++)
195 if (dev
->resource
[i
].flags
&& dev
->resource
[i
].start
)
196 pci_claim_resource(dev
, i
);
203 if (!alpha_mv
.init_pci
)
209 pcibios_setup(char *str
)
215 pcibios_fixup_resource(struct resource
*res
, struct resource
*root
)
217 res
->start
+= root
->start
;
218 res
->end
+= root
->start
;
222 pcibios_fixup_device_resources(struct pci_dev
*dev
, struct pci_bus
*bus
)
224 /* Update device resources. */
228 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++) {
229 if (!dev
->resource
[i
].start
)
231 if (dev
->resource
[i
].flags
& IORESOURCE_IO
)
232 pcibios_fixup_resource(&dev
->resource
[i
],
234 else if (dev
->resource
[i
].flags
& IORESOURCE_MEM
)
235 pcibios_fixup_resource(&dev
->resource
[i
],
238 pcibios_assign_special(dev
);
242 pcibios_fixup_bus(struct pci_bus
*bus
)
244 /* Propogate hose info into the subordinate devices. */
246 struct pci_controler
*hose
= (struct pci_controler
*) bus
->sysdata
;
249 bus
->resource
[0] = hose
->io_space
;
250 bus
->resource
[1] = hose
->mem_space
;
251 for (dev
= bus
->devices
; dev
; dev
= dev
->sibling
) {
252 if ((dev
->class >> 8) != PCI_CLASS_BRIDGE_PCI
)
253 pcibios_fixup_device_resources(dev
, bus
);
258 pcibios_update_resource(struct pci_dev
*dev
, struct resource
*root
,
259 struct resource
*res
, int resource
)
264 where
= PCI_BASE_ADDRESS_0
+ (resource
* 4);
265 reg
= (res
->start
- root
->start
) | (res
->flags
& 0xf);
266 pci_write_config_dword(dev
, where
, reg
);
267 if ((res
->flags
& (PCI_BASE_ADDRESS_SPACE
268 | PCI_BASE_ADDRESS_MEM_TYPE_MASK
))
269 == (PCI_BASE_ADDRESS_SPACE_MEMORY
270 | PCI_BASE_ADDRESS_MEM_TYPE_64
)) {
271 pci_write_config_dword(dev
, where
+4, 0);
272 printk(KERN_WARNING
"PCI: dev %s type 64-bit\n", dev
->name
);
275 /* ??? FIXME -- record old value for shutdown. */
279 pcibios_update_irq(struct pci_dev
*dev
, int irq
)
281 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, irq
);
283 /* ??? FIXME -- record old value for shutdown. */
286 /* Most Alphas have straight-forward swizzling needs. */
289 common_swizzle(struct pci_dev
*dev
, u8
*pinp
)
291 struct pci_controler
*hose
= dev
->sysdata
;
293 if (dev
->bus
->number
!= hose
->first_busno
) {
296 pin
= bridge_swizzle(pin
, PCI_SLOT(dev
->devfn
));
297 /* Move up the chain of bridges. */
298 dev
= dev
->bus
->self
;
299 } while (dev
->bus
->self
);
302 /* The slot is the slot of the last bridge. */
305 return PCI_SLOT(dev
->devfn
);
309 pcibios_fixup_pbus_ranges(struct pci_bus
* bus
,
310 struct pbus_set_ranges_data
* ranges
)
312 ranges
->io_start
-= bus
->resource
[0]->start
;
313 ranges
->io_end
-= bus
->resource
[0]->start
;
314 ranges
->mem_start
-= bus
->resource
[1]->start
;
315 ranges
->mem_end
-= bus
->resource
[1]->start
;
319 common_init_pci(void)
321 struct pci_controler
*hose
;
325 /* Scan all of the recorded PCI controlers. */
326 for (next_busno
= 0, hose
= hose_head
; hose
; hose
= hose
->next
) {
327 hose
->first_busno
= next_busno
;
328 hose
->last_busno
= 0xff;
329 bus
= pci_scan_bus(next_busno
, alpha_mv
.pci_ops
, hose
);
331 next_busno
= hose
->last_busno
= bus
->subordinate
;
335 pci_assign_unassigned_resources(alpha_mv
.min_io_address
,
336 alpha_mv
.min_mem_address
);
337 pci_fixup_irqs(alpha_mv
.pci_swizzle
, alpha_mv
.pci_map_irq
);
338 pci_set_bus_ranges();
342 struct pci_controler
* __init
343 alloc_pci_controler(void)
345 struct pci_controler
*hose
;
347 hose
= alloc_bootmem(sizeof(*hose
));
350 hose_tail
= &hose
->next
;
355 struct resource
* __init
358 struct resource
*res
;
360 res
= alloc_bootmem(sizeof(*res
));