2 * bios32.c - PCI BIOS functions for m68k systems.
4 * Written by Wout Klaren.
6 * Based on the DEC Alpha bios32.c by Dave Rusling and David Mosberger.
9 #include <linux/init.h>
10 #include <linux/kernel.h>
13 # define DBG_DEVS(args) printk args
15 # define DBG_DEVS(args)
21 * PCI support for Linux/m68k. Currently only the Hades is supported.
23 * The support for PCI bridges in the DEC Alpha version has
24 * been removed in this version.
27 #include <linux/pci.h>
28 #include <linux/slab.h>
33 #include <asm/uaccess.h>
43 * Align VAL to ALIGN, which must be a power of two.
46 #define ALIGN(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
49 * Offsets relative to the I/O and memory base addresses from where resources
53 #define IO_ALLOC_OFFSET 0x00004000
54 #define MEM_ALLOC_OFFSET 0x04000000
57 * Declarations of hardware specific initialisation functions.
60 extern struct pci_bus_info
*init_hades_pci(void);
63 * Bus info structure of the PCI bus. A pointer to this structure is
64 * put in the sysdata member of the pci_bus structure.
67 static struct pci_bus_info
*bus_info
;
69 static int pci_modify
= 1; /* If set, layout the PCI bus ourself. */
70 static int skip_vga
; /* If set do not modify base addresses
72 static int disable_pci_burst
; /* If set do not allow PCI bursts. */
74 static unsigned int io_base
;
75 static unsigned int mem_base
;
78 * static void disable_dev(struct pci_dev *dev)
80 * Disable PCI device DEV so that it does not respond to I/O or memory
85 * dev - device to disable.
88 static void __init
disable_dev(struct pci_dev
*dev
)
92 if (((dev
->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA
) ||
93 (dev
->class >> 8 == PCI_CLASS_DISPLAY_VGA
) ||
94 (dev
->class >> 8 == PCI_CLASS_DISPLAY_XGA
)) && skip_vga
)
97 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
99 cmd
&= (~PCI_COMMAND_IO
& ~PCI_COMMAND_MEMORY
& ~PCI_COMMAND_MASTER
);
100 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
104 * static void layout_dev(struct pci_dev *dev)
106 * Layout memory and I/O for a device.
110 * device - device to layout memory and I/O for.
113 static void __init
layout_dev(struct pci_dev
*dev
)
116 unsigned int base
, mask
, size
, reg
;
117 unsigned int alignto
;
121 * Skip video cards if requested.
124 if (((dev
->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA
) ||
125 (dev
->class >> 8 == PCI_CLASS_DISPLAY_VGA
) ||
126 (dev
->class >> 8 == PCI_CLASS_DISPLAY_XGA
)) && skip_vga
)
129 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
131 for (reg
= PCI_BASE_ADDRESS_0
, i
= 0; reg
<= PCI_BASE_ADDRESS_5
; reg
+= 4, i
++)
134 * Figure out how much space and of what type this
138 pci_write_config_dword(dev
, reg
, 0xffffffff);
139 pci_read_config_dword(dev
, reg
, &base
);
143 /* this base-address register is unused */
144 dev
->resource
[i
].start
= 0;
145 dev
->resource
[i
].end
= 0;
146 dev
->resource
[i
].flags
= 0;
151 * We've read the base address register back after
152 * writing all ones and so now we must decode it.
155 if (base
& PCI_BASE_ADDRESS_SPACE_IO
)
158 * I/O space base address register.
161 cmd
|= PCI_COMMAND_IO
;
163 base
&= PCI_BASE_ADDRESS_IO_MASK
;
164 mask
= (~base
<< 1) | 0x1;
165 size
= (mask
& base
) & 0xffffffff;
168 * Align to multiple of size of minimum base.
171 alignto
= max_t(unsigned int, 0x040, size
);
172 base
= ALIGN(io_base
, alignto
);
173 io_base
= base
+ size
;
174 pci_write_config_dword(dev
, reg
, base
| PCI_BASE_ADDRESS_SPACE_IO
);
176 dev
->resource
[i
].start
= base
;
177 dev
->resource
[i
].end
= dev
->resource
[i
].start
+ size
- 1;
178 dev
->resource
[i
].flags
= IORESOURCE_IO
| PCI_BASE_ADDRESS_SPACE_IO
;
180 DBG_DEVS(("layout_dev: IO address: %lX\n", base
));
187 * Memory space base address register.
190 cmd
|= PCI_COMMAND_MEMORY
;
191 type
= base
& PCI_BASE_ADDRESS_MEM_TYPE_MASK
;
192 base
&= PCI_BASE_ADDRESS_MEM_MASK
;
193 mask
= (~base
<< 1) | 0x1;
194 size
= (mask
& base
) & 0xffffffff;
197 case PCI_BASE_ADDRESS_MEM_TYPE_32
:
198 case PCI_BASE_ADDRESS_MEM_TYPE_64
:
201 case PCI_BASE_ADDRESS_MEM_TYPE_1M
:
202 printk("bios32 WARNING: slot %d, function %d "
203 "requests memory below 1MB---don't "
204 "know how to do that.\n",
205 PCI_SLOT(dev
->devfn
),
206 PCI_FUNC(dev
->devfn
));
211 * Align to multiple of size of minimum base.
214 alignto
= max_t(unsigned int, 0x1000, size
);
215 base
= ALIGN(mem_base
, alignto
);
216 mem_base
= base
+ size
;
217 pci_write_config_dword(dev
, reg
, base
);
219 dev
->resource
[i
].start
= base
;
220 dev
->resource
[i
].end
= dev
->resource
[i
].start
+ size
- 1;
221 dev
->resource
[i
].flags
= IORESOURCE_MEM
;
223 if (type
== PCI_BASE_ADDRESS_MEM_TYPE_64
)
226 * 64-bit address, set the highest 32 bits
231 pci_write_config_dword(dev
, reg
, 0);
234 dev
->resource
[i
].start
= 0;
235 dev
->resource
[i
].end
= 0;
236 dev
->resource
[i
].flags
= 0;
245 if (dev
->class >> 8 == PCI_CLASS_NOT_DEFINED
||
246 dev
->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA
||
247 dev
->class >> 8 == PCI_CLASS_DISPLAY_VGA
||
248 dev
->class >> 8 == PCI_CLASS_DISPLAY_XGA
)
251 * All of these (may) have I/O scattered all around
252 * and may not use i/o-base address registers at all.
253 * So we just have to always enable I/O to these
256 cmd
|= PCI_COMMAND_IO
;
259 pci_write_config_word(dev
, PCI_COMMAND
, cmd
| PCI_COMMAND_MASTER
);
261 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, (disable_pci_burst
) ? 0 : 32);
263 if (bus_info
!= NULL
)
264 bus_info
->conf_device(dev
); /* Machine dependent configuration. */
266 DBG_DEVS(("layout_dev: bus %d slot 0x%x VID 0x%x DID 0x%x class 0x%x\n",
267 dev
->bus
->number
, PCI_SLOT(dev
->devfn
), dev
->vendor
, dev
->device
, dev
->class));
271 * static void layout_bus(struct pci_bus *bus)
273 * Layout memory and I/O for all devices on the given bus.
280 static void __init
layout_bus(struct pci_bus
*bus
)
282 unsigned int bio
, bmem
;
285 DBG_DEVS(("layout_bus: starting bus %d\n", bus
->number
));
287 if (!bus
->devices
&& !bus
->children
)
291 * Align the current bases on appropriate boundaries (4K for
292 * IO and 1MB for memory).
295 bio
= io_base
= ALIGN(io_base
, 4*KB
);
296 bmem
= mem_base
= ALIGN(mem_base
, 1*MB
);
299 * PCI devices might have been setup by a PCI BIOS emulation
300 * running under TOS. In these cases there is a
301 * window during which two devices may have an overlapping
302 * address range. To avoid this causing trouble, we first
303 * turn off the I/O and memory address decoders for all PCI
304 * devices. They'll be re-enabled only once all address
305 * decoders are programmed consistently.
308 DBG_DEVS(("layout_bus: disable_dev for bus %d\n", bus
->number
));
310 for (dev
= bus
->devices
; dev
; dev
= dev
->sibling
)
312 if ((dev
->class >> 16 != PCI_BASE_CLASS_BRIDGE
) ||
313 (dev
->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA
))
318 * Allocate space to each device:
321 DBG_DEVS(("layout_bus: starting bus %d devices\n", bus
->number
));
323 for (dev
= bus
->devices
; dev
; dev
= dev
->sibling
)
325 if ((dev
->class >> 16 != PCI_BASE_CLASS_BRIDGE
) ||
326 (dev
->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA
))
330 DBG_DEVS(("layout_bus: bus %d finished\n", bus
->number
));
334 * static void pcibios_fixup(void)
336 * Layout memory and I/O of all devices on the PCI bus if 'pci_modify' is
337 * true. This might be necessary because not every m68k machine with a PCI
338 * bus has a PCI BIOS. This function should be called right after
339 * pci_scan_bus() in pcibios_init().
342 static void __init
pcibios_fixup(void)
347 * Set base addresses for allocation of I/O and memory space.
350 io_base
= bus_info
->io_space
.start
+ IO_ALLOC_OFFSET
;
351 mem_base
= bus_info
->mem_space
.start
+ MEM_ALLOC_OFFSET
;
354 * Scan the tree, allocating PCI memory and I/O space.
357 layout_bus(pci_bus_b(pci_root
.next
));
361 * Fix interrupt assignments, etc.
364 bus_info
->fixup(pci_modify
);
368 * static void pcibios_claim_resources(struct pci_bus *bus)
370 * Claim all resources that are assigned to devices on the given bus.
377 static void __init
pcibios_claim_resources(struct pci_bus
*bus
)
384 for (dev
= bus
->devices
; (dev
!= NULL
); dev
= dev
->sibling
)
386 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++)
388 struct resource
*r
= &dev
->resource
[i
];
390 struct pci_bus_info
*bus_info
= (struct pci_bus_info
*) dev
->sysdata
;
392 if ((r
->start
== 0) || (r
->parent
!= NULL
))
395 if (r
->flags
& IORESOURCE_IO
)
396 pr
= &bus_info
->io_space
;
398 pr
= &bus_info
->mem_space
;
400 if (r
->flags
& IORESOURCE_IO
)
401 pr
= &ioport_resource
;
403 pr
= &iomem_resource
;
405 if (request_resource(pr
, r
) < 0)
407 printk(KERN_ERR
"PCI: Address space collision on region %d of device %s\n", i
, dev
->name
);
413 pcibios_claim_resources(bus
->children
);
420 * int pcibios_assign_resource(struct pci_dev *dev, int i)
422 * Assign a new address to a PCI resource.
429 * Result: 0 if successful.
432 int __init
pcibios_assign_resource(struct pci_dev
*dev
, int i
)
434 struct resource
*r
= &dev
->resource
[i
];
435 struct resource
*pr
= pci_find_parent_resource(dev
, r
);
436 unsigned long size
= r
->end
+ 1;
441 if (r
->flags
& IORESOURCE_IO
)
446 if (allocate_resource(pr
, r
, size
, bus_info
->io_space
.start
+
447 IO_ALLOC_OFFSET
, bus_info
->io_space
.end
, 1024))
452 if (allocate_resource(pr
, r
, size
, bus_info
->mem_space
.start
+
453 MEM_ALLOC_OFFSET
, bus_info
->mem_space
.end
, size
))
458 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
+ 4 * i
, r
->start
);
463 void __init
pcibios_fixup_bus(struct pci_bus
*bus
)
468 sysdata
= (bus
->parent
) ? bus
->parent
->sysdata
: bus
->sysdata
;
470 for (dev
= bus
->devices
; (dev
!= NULL
); dev
= dev
->sibling
)
471 dev
->sysdata
= sysdata
;
474 void __init
pcibios_init(void)
476 printk("Linux/m68k PCI BIOS32 revision %x.%02x\n", MAJOR_REV
, MINOR_REV
);
481 bus_info
= init_hades_pci();
483 if (bus_info
!= NULL
)
485 printk("PCI: Probing PCI hardware\n");
486 pci_scan_bus(0, bus_info
->m68k_pci_ops
, bus_info
);
488 pcibios_claim_resources(pci_root
);
491 printk("PCI: No PCI bus detected\n");
494 char * __init
pcibios_setup(char *str
)
496 if (!strcmp(str
, "nomodify"))
501 else if (!strcmp(str
, "skipvga"))
506 else if (!strcmp(str
, "noburst"))
508 disable_pci_burst
= 1;
514 #endif /* CONFIG_PCI */