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/config.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
14 # define DBG_DEVS(args) printk args
16 # define DBG_DEVS(args)
22 * PCI support for Linux/m68k. Currently only the Hades is supported.
24 * The support for PCI bridges in the DEC Alpha version has
25 * been removed in this version.
28 #include <linux/pci.h>
29 #include <linux/slab.h>
34 #include <asm/uaccess.h>
44 * Align VAL to ALIGN, which must be a power of two.
47 #define ALIGN(val,align) (((val) + ((align) - 1)) & ~((align) - 1))
49 #define MAX(val1, val2) (((val1) > (val2)) ? val1 : val2)
52 * Offsets relative to the I/O and memory base addresses from where resources
56 #define IO_ALLOC_OFFSET 0x00004000
57 #define MEM_ALLOC_OFFSET 0x04000000
60 * Declarations of hardware specific initialisation functions.
63 extern struct pci_bus_info
*init_hades_pci(void);
66 * Bus info structure of the PCI bus. A pointer to this structure is
67 * put in the sysdata member of the pci_bus structure.
70 static struct pci_bus_info
*bus_info
;
72 static int pci_modify
= 1; /* If set, layout the PCI bus ourself. */
73 static int skip_vga
; /* If set do not modify base addresses
75 static int disable_pci_burst
; /* If set do not allow PCI bursts. */
77 static unsigned int io_base
;
78 static unsigned int mem_base
;
81 * static void disable_dev(struct pci_dev *dev)
83 * Disable PCI device DEV so that it does not respond to I/O or memory
88 * dev - device to disable.
91 static void __init
disable_dev(struct pci_dev
*dev
)
95 if (((dev
->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA
) ||
96 (dev
->class >> 8 == PCI_CLASS_DISPLAY_VGA
) ||
97 (dev
->class >> 8 == PCI_CLASS_DISPLAY_XGA
)) && skip_vga
)
100 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
102 cmd
&= (~PCI_COMMAND_IO
& ~PCI_COMMAND_MEMORY
& ~PCI_COMMAND_MASTER
);
103 pci_write_config_word(dev
, PCI_COMMAND
, cmd
);
107 * static void layout_dev(struct pci_dev *dev)
109 * Layout memory and I/O for a device.
113 * device - device to layout memory and I/O for.
116 static void __init
layout_dev(struct pci_dev
*dev
)
119 unsigned int base
, mask
, size
, reg
;
120 unsigned int alignto
;
124 * Skip video cards if requested.
127 if (((dev
->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA
) ||
128 (dev
->class >> 8 == PCI_CLASS_DISPLAY_VGA
) ||
129 (dev
->class >> 8 == PCI_CLASS_DISPLAY_XGA
)) && skip_vga
)
132 pci_read_config_word(dev
, PCI_COMMAND
, &cmd
);
134 for (reg
= PCI_BASE_ADDRESS_0
, i
= 0; reg
<= PCI_BASE_ADDRESS_5
; reg
+= 4, i
++)
137 * Figure out how much space and of what type this
141 pci_write_config_dword(dev
, reg
, 0xffffffff);
142 pci_read_config_dword(dev
, reg
, &base
);
146 /* this base-address register is unused */
147 dev
->resource
[i
].start
= 0;
148 dev
->resource
[i
].end
= 0;
149 dev
->resource
[i
].flags
= 0;
154 * We've read the base address register back after
155 * writing all ones and so now we must decode it.
158 if (base
& PCI_BASE_ADDRESS_SPACE_IO
)
161 * I/O space base address register.
164 cmd
|= PCI_COMMAND_IO
;
166 base
&= PCI_BASE_ADDRESS_IO_MASK
;
167 mask
= (~base
<< 1) | 0x1;
168 size
= (mask
& base
) & 0xffffffff;
171 * Align to multiple of size of minimum base.
174 alignto
= MAX(0x040, size
) ;
175 base
= ALIGN(io_base
, alignto
);
176 io_base
= base
+ size
;
177 pci_write_config_dword(dev
, reg
, base
| PCI_BASE_ADDRESS_SPACE_IO
);
179 dev
->resource
[i
].start
= base
;
180 dev
->resource
[i
].end
= dev
->resource
[i
].start
+ size
- 1;
181 dev
->resource
[i
].flags
= IORESOURCE_IO
| PCI_BASE_ADDRESS_SPACE_IO
;
183 DBG_DEVS(("layout_dev: IO address: %lX\n", base
));
190 * Memory space base address register.
193 cmd
|= PCI_COMMAND_MEMORY
;
194 type
= base
& PCI_BASE_ADDRESS_MEM_TYPE_MASK
;
195 base
&= PCI_BASE_ADDRESS_MEM_MASK
;
196 mask
= (~base
<< 1) | 0x1;
197 size
= (mask
& base
) & 0xffffffff;
200 case PCI_BASE_ADDRESS_MEM_TYPE_32
:
201 case PCI_BASE_ADDRESS_MEM_TYPE_64
:
204 case PCI_BASE_ADDRESS_MEM_TYPE_1M
:
205 printk("bios32 WARNING: slot %d, function %d "
206 "requests memory below 1MB---don't "
207 "know how to do that.\n",
208 PCI_SLOT(dev
->devfn
),
209 PCI_FUNC(dev
->devfn
));
214 * Align to multiple of size of minimum base.
217 alignto
= MAX(0x1000, size
) ;
218 base
= ALIGN(mem_base
, alignto
);
219 mem_base
= base
+ size
;
220 pci_write_config_dword(dev
, reg
, base
);
222 dev
->resource
[i
].start
= base
;
223 dev
->resource
[i
].end
= dev
->resource
[i
].start
+ size
- 1;
224 dev
->resource
[i
].flags
= IORESOURCE_MEM
;
226 if (type
== PCI_BASE_ADDRESS_MEM_TYPE_64
)
229 * 64-bit address, set the highest 32 bits
234 pci_write_config_dword(dev
, reg
, 0);
237 dev
->resource
[i
].start
= 0;
238 dev
->resource
[i
].end
= 0;
239 dev
->resource
[i
].flags
= 0;
248 if (dev
->class >> 8 == PCI_CLASS_NOT_DEFINED
||
249 dev
->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA
||
250 dev
->class >> 8 == PCI_CLASS_DISPLAY_VGA
||
251 dev
->class >> 8 == PCI_CLASS_DISPLAY_XGA
)
254 * All of these (may) have I/O scattered all around
255 * and may not use i/o-base address registers at all.
256 * So we just have to always enable I/O to these
259 cmd
|= PCI_COMMAND_IO
;
262 pci_write_config_word(dev
, PCI_COMMAND
, cmd
| PCI_COMMAND_MASTER
);
264 pci_write_config_byte(dev
, PCI_LATENCY_TIMER
, (disable_pci_burst
) ? 0 : 32);
266 if (bus_info
!= NULL
)
267 bus_info
->conf_device(dev
); /* Machine dependent configuration. */
269 DBG_DEVS(("layout_dev: bus %d slot 0x%x VID 0x%x DID 0x%x class 0x%x\n",
270 dev
->bus
->number
, PCI_SLOT(dev
->devfn
), dev
->vendor
, dev
->device
, dev
->class));
274 * static void layout_bus(struct pci_bus *bus)
276 * Layout memory and I/O for all devices on the given bus.
283 static void __init
layout_bus(struct pci_bus
*bus
)
285 unsigned int bio
, bmem
;
288 DBG_DEVS(("layout_bus: starting bus %d\n", bus
->number
));
290 if (!bus
->devices
&& !bus
->children
)
294 * Align the current bases on appropriate boundaries (4K for
295 * IO and 1MB for memory).
298 bio
= io_base
= ALIGN(io_base
, 4*KB
);
299 bmem
= mem_base
= ALIGN(mem_base
, 1*MB
);
302 * PCI devices might have been setup by a PCI BIOS emulation
303 * running under TOS. In these cases there is a
304 * window during which two devices may have an overlapping
305 * address range. To avoid this causing trouble, we first
306 * turn off the I/O and memory address decoders for all PCI
307 * devices. They'll be re-enabled only once all address
308 * decoders are programmed consistently.
311 DBG_DEVS(("layout_bus: disable_dev for bus %d\n", bus
->number
));
313 for (dev
= bus
->devices
; dev
; dev
= dev
->sibling
)
315 if ((dev
->class >> 16 != PCI_BASE_CLASS_BRIDGE
) ||
316 (dev
->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA
))
321 * Allocate space to each device:
324 DBG_DEVS(("layout_bus: starting bus %d devices\n", bus
->number
));
326 for (dev
= bus
->devices
; dev
; dev
= dev
->sibling
)
328 if ((dev
->class >> 16 != PCI_BASE_CLASS_BRIDGE
) ||
329 (dev
->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA
))
333 DBG_DEVS(("layout_bus: bus %d finished\n", bus
->number
));
337 * static void pcibios_fixup(void)
339 * Layout memory and I/O of all devices on the PCI bus if 'pci_modify' is
340 * true. This might be necessary because not every m68k machine with a PCI
341 * bus has a PCI BIOS. This function should be called right after
342 * pci_scan_bus() in pcibios_init().
345 static void __init
pcibios_fixup(void)
350 * Set base addresses for allocation of I/O and memory space.
353 io_base
= bus_info
->io_space
.start
+ IO_ALLOC_OFFSET
;
354 mem_base
= bus_info
->mem_space
.start
+ MEM_ALLOC_OFFSET
;
357 * Scan the tree, allocating PCI memory and I/O space.
360 layout_bus(pci_bus_b(pci_root
.next
));
364 * Fix interrupt assignments, etc.
367 bus_info
->fixup(pci_modify
);
371 * static void pcibios_claim_resources(struct pci_bus *bus)
373 * Claim all resources that are assigned to devices on the given bus.
380 static void __init
pcibios_claim_resources(struct pci_bus
*bus
)
387 for (dev
= bus
->devices
; (dev
!= NULL
); dev
= dev
->sibling
)
389 for (i
= 0; i
< PCI_NUM_RESOURCES
; i
++)
391 struct resource
*r
= &dev
->resource
[i
];
393 struct pci_bus_info
*bus_info
= (struct pci_bus_info
*) dev
->sysdata
;
395 if ((r
->start
== 0) || (r
->parent
!= NULL
))
398 if (r
->flags
& IORESOURCE_IO
)
399 pr
= &bus_info
->io_space
;
401 pr
= &bus_info
->mem_space
;
403 if (r
->flags
& IORESOURCE_IO
)
404 pr
= &ioport_resource
;
406 pr
= &iomem_resource
;
408 if (request_resource(pr
, r
) < 0)
410 printk(KERN_ERR
"PCI: Address space collision on region %d of device %s\n", i
, dev
->name
);
416 pcibios_claim_resources(bus
->children
);
423 * int pcibios_assign_resource(struct pci_dev *dev, int i)
425 * Assign a new address to a PCI resource.
432 * Result: 0 if successful.
435 int __init
pcibios_assign_resource(struct pci_dev
*dev
, int i
)
437 struct resource
*r
= &dev
->resource
[i
];
438 struct resource
*pr
= pci_find_parent_resource(dev
, r
);
439 unsigned long size
= r
->end
+ 1;
444 if (r
->flags
& IORESOURCE_IO
)
449 if (allocate_resource(pr
, r
, size
, bus_info
->io_space
.start
+
450 IO_ALLOC_OFFSET
, bus_info
->io_space
.end
, 1024))
455 if (allocate_resource(pr
, r
, size
, bus_info
->mem_space
.start
+
456 MEM_ALLOC_OFFSET
, bus_info
->mem_space
.end
, size
))
461 pci_write_config_dword(dev
, PCI_BASE_ADDRESS_0
+ 4 * i
, r
->start
);
466 void __init
pcibios_fixup_bus(struct pci_bus
*bus
)
471 sysdata
= (bus
->parent
) ? bus
->parent
->sysdata
: bus
->sysdata
;
473 for (dev
= bus
->devices
; (dev
!= NULL
); dev
= dev
->sibling
)
474 dev
->sysdata
= sysdata
;
477 void __init
pcibios_init(void)
479 printk("Linux/m68k PCI BIOS32 revision %x.%02x\n", MAJOR_REV
, MINOR_REV
);
484 bus_info
= init_hades_pci();
486 if (bus_info
!= NULL
)
488 printk("PCI: Probing PCI hardware\n");
489 pci_scan_bus(0, bus_info
->m68k_pci_ops
, bus_info
);
491 pcibios_claim_resources(pci_root
);
494 printk("PCI: No PCI bus detected\n");
497 char * __init
pcibios_setup(char *str
)
499 if (!strcmp(str
, "nomodify"))
504 else if (!strcmp(str
, "skipvga"))
509 else if (!strcmp(str
, "noburst"))
511 disable_pci_burst
= 1;
517 #endif /* CONFIG_PCI */