pci.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * FSL SoC setup code
  3. *
  4. * Maintained by Kumar Gala (see MAINTAINERS for contact information)
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/config.h>
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/errno.h>
  16. #include <linux/pci.h>
  17. #include <linux/delay.h>
  18. #include <linux/irq.h>
  19. #include <linux/module.h>
  20. #include <asm/system.h>
  21. #include <asm/atomic.h>
  22. #include <asm/io.h>
  23. #include <asm/pci-bridge.h>
  24. #include <asm/prom.h>
  25. #include <sysdev/fsl_soc.h>
  26. #undef DEBUG
  27. #ifdef DEBUG
  28. #define DBG(x...) printk(x)
  29. #else
  30. #define DBG(x...)
  31. #endif
  32. int mpc83xx_pci2_busno;
  33. int mpc83xx_exclude_device(u_char bus, u_char devfn)
  34. {
  35. if (bus == 0 && PCI_SLOT(devfn) == 0)
  36. return PCIBIOS_DEVICE_NOT_FOUND;
  37. if (mpc83xx_pci2_busno)
  38. if (bus == (mpc83xx_pci2_busno) && PCI_SLOT(devfn) == 0)
  39. return PCIBIOS_DEVICE_NOT_FOUND;
  40. return PCIBIOS_SUCCESSFUL;
  41. }
  42. int __init add_bridge(struct device_node *dev)
  43. {
  44. int len;
  45. struct pci_controller *hose;
  46. struct resource rsrc;
  47. int *bus_range;
  48. int primary = 1, has_address = 0;
  49. phys_addr_t immr = get_immrbase();
  50. DBG("Adding PCI host bridge %s\n", dev->full_name);
  51. /* Fetch host bridge registers address */
  52. has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
  53. /* Get bus range if any */
  54. bus_range = (int *)get_property(dev, "bus-range", &len);
  55. if (bus_range == NULL || len < 2 * sizeof(int)) {
  56. printk(KERN_WARNING "Can't get bus-range for %s, assume"
  57. " bus 0\n", dev->full_name);
  58. }
  59. hose = pcibios_alloc_controller();
  60. if (!hose)
  61. return -ENOMEM;
  62. hose->arch_data = dev;
  63. hose->set_cfg_type = 1;
  64. hose->first_busno = bus_range ? bus_range[0] : 0;
  65. hose->last_busno = bus_range ? bus_range[1] : 0xff;
  66. /* MPC83xx supports up to two host controllers one at 0x8500 from immrbar
  67. * the other at 0x8600, we consider the 0x8500 the primary controller
  68. */
  69. /* PCI 1 */
  70. if ((rsrc.start & 0xfffff) == 0x8500) {
  71. setup_indirect_pci(hose, immr + 0x8300, immr + 0x8304);
  72. }
  73. /* PCI 2 */
  74. if ((rsrc.start & 0xfffff) == 0x8600) {
  75. setup_indirect_pci(hose, immr + 0x8380, immr + 0x8384);
  76. primary = 0;
  77. hose->bus_offset = hose->first_busno;
  78. mpc83xx_pci2_busno = hose->first_busno;
  79. }
  80. printk(KERN_INFO "Found MPC83xx PCI host bridge at 0x%08lx. "
  81. "Firmware bus number: %d->%d\n",
  82. rsrc.start, hose->first_busno, hose->last_busno);
  83. DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
  84. hose, hose->cfg_addr, hose->cfg_data);
  85. /* Interpret the "ranges" property */
  86. /* This also maps the I/O region and sets isa_io/mem_base */
  87. pci_process_bridge_OF_ranges(hose, dev, primary);
  88. return 0;
  89. }