initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / m68k / kernel / bios32.c
blob738531ca2d382b297cdceb90f3e1ca9538b1b14e
1 /*
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.
7 */
9 #include <linux/config.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
13 #if 0
14 # define DBG_DEVS(args) printk args
15 #else
16 # define DBG_DEVS(args)
17 #endif
19 #ifdef CONFIG_PCI
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>
30 #include <linux/mm.h>
32 #include <asm/io.h>
33 #include <asm/pci.h>
34 #include <asm/uaccess.h>
36 #define KB 1024
37 #define MB (1024*KB)
38 #define GB (1024*MB)
40 #define MAJOR_REV 0
41 #define MINOR_REV 5
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
53 * are allocated.
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
74 of vga cards.*/
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
84 * accesses.
86 * Parameters:
88 * dev - device to disable.
91 static void __init disable_dev(struct pci_dev *dev)
93 unsigned short cmd;
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)
98 return;
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.
111 * Parameters:
113 * device - device to layout memory and I/O for.
116 static void __init layout_dev(struct pci_dev *dev)
118 unsigned short cmd;
119 unsigned int base, mask, size, reg;
120 unsigned int alignto;
121 int i;
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)
130 return;
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
138 * device wants.
141 pci_write_config_dword(dev, reg, 0xffffffff);
142 pci_read_config_dword(dev, reg, &base);
144 if (!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;
150 continue;
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));
185 else
187 unsigned int type;
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;
198 switch (type)
200 case PCI_BASE_ADDRESS_MEM_TYPE_32:
201 case PCI_BASE_ADDRESS_MEM_TYPE_64:
202 break;
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));
210 continue;
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
230 * to zero.
233 reg += 4;
234 pci_write_config_dword(dev, reg, 0);
236 i++;
237 dev->resource[i].start = 0;
238 dev->resource[i].end = 0;
239 dev->resource[i].flags = 0;
245 * Enable device:
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
257 * devices.
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.
278 * Parameters:
280 * bus - bus.
283 static void __init layout_bus(struct pci_bus *bus)
285 unsigned int bio, bmem;
286 struct pci_dev *dev;
288 DBG_DEVS(("layout_bus: starting bus %d\n", bus->number));
290 if (!bus->devices && !bus->children)
291 return;
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))
317 disable_dev(dev);
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))
330 layout_dev(dev);
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)
347 if (pci_modify)
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.
375 * Parameters:
377 * bus - bus.
380 static void __init pcibios_claim_resources(struct pci_bus *bus)
382 struct pci_dev *dev;
383 int i;
385 while (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];
392 struct resource *pr;
393 struct pci_bus_info *bus_info = (struct pci_bus_info *) dev->sysdata;
395 if ((r->start == 0) || (r->parent != NULL))
396 continue;
397 #if 1
398 if (r->flags & IORESOURCE_IO)
399 pr = &bus_info->io_space;
400 else
401 pr = &bus_info->mem_space;
402 #else
403 if (r->flags & IORESOURCE_IO)
404 pr = &ioport_resource;
405 else
406 pr = &iomem_resource;
407 #endif
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);
415 if (bus->children)
416 pcibios_claim_resources(bus->children);
418 bus = bus->next;
423 * int pcibios_assign_resource(struct pci_dev *dev, int i)
425 * Assign a new address to a PCI resource.
427 * Parameters:
429 * dev - device.
430 * i - 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;
441 if (!pr)
442 return -EINVAL;
444 if (r->flags & IORESOURCE_IO)
446 if (size > 0x100)
447 return -EFBIG;
449 if (allocate_resource(pr, r, size, bus_info->io_space.start +
450 IO_ALLOC_OFFSET, bus_info->io_space.end, 1024))
451 return -EBUSY;
453 else
455 if (allocate_resource(pr, r, size, bus_info->mem_space.start +
456 MEM_ALLOC_OFFSET, bus_info->mem_space.end, size))
457 return -EBUSY;
460 if (i < 6)
461 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, r->start);
463 return 0;
466 void __init pcibios_fixup_bus(struct pci_bus *bus)
468 struct pci_dev *dev;
469 void *sysdata;
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);
481 bus_info = NULL;
482 #ifdef CONFIG_HADES
483 if (MACH_IS_HADES)
484 bus_info = init_hades_pci();
485 #endif
486 if (bus_info != NULL)
488 printk("PCI: Probing PCI hardware\n");
489 pci_scan_bus(0, bus_info->m68k_pci_ops, bus_info);
490 pcibios_fixup();
491 pcibios_claim_resources(pci_root);
493 else
494 printk("PCI: No PCI bus detected\n");
497 char * __init pcibios_setup(char *str)
499 if (!strcmp(str, "nomodify"))
501 pci_modify = 0;
502 return NULL;
504 else if (!strcmp(str, "skipvga"))
506 skip_vga = 1;
507 return NULL;
509 else if (!strcmp(str, "noburst"))
511 disable_pci_burst = 1;
512 return NULL;
515 return str;
517 #endif /* CONFIG_PCI */