pci-xlr.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
  3. * reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the NetLogic
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <linux/types.h>
  35. #include <linux/pci.h>
  36. #include <linux/kernel.h>
  37. #include <linux/init.h>
  38. #include <linux/mm.h>
  39. #include <linux/console.h>
  40. #include <asm/io.h>
  41. #include <asm/netlogic/interrupt.h>
  42. #include <asm/netlogic/xlr/iomap.h>
  43. #include <asm/netlogic/xlr/pic.h>
  44. #include <asm/netlogic/xlr/xlr.h>
  45. static void *pci_config_base;
  46. #define pci_cfg_addr(bus, devfn, off) (((bus) << 16) | ((devfn) << 8) | (off))
  47. /* PCI ops */
  48. static inline u32 pci_cfg_read_32bit(struct pci_bus *bus, unsigned int devfn,
  49. int where)
  50. {
  51. u32 data;
  52. u32 *cfgaddr;
  53. cfgaddr = (u32 *)(pci_config_base +
  54. pci_cfg_addr(bus->number, devfn, where & ~3));
  55. data = *cfgaddr;
  56. return cpu_to_le32(data);
  57. }
  58. static inline void pci_cfg_write_32bit(struct pci_bus *bus, unsigned int devfn,
  59. int where, u32 data)
  60. {
  61. u32 *cfgaddr;
  62. cfgaddr = (u32 *)(pci_config_base +
  63. pci_cfg_addr(bus->number, devfn, where & ~3));
  64. *cfgaddr = cpu_to_le32(data);
  65. }
  66. static int nlm_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  67. int where, int size, u32 *val)
  68. {
  69. u32 data;
  70. if ((size == 2) && (where & 1))
  71. return PCIBIOS_BAD_REGISTER_NUMBER;
  72. else if ((size == 4) && (where & 3))
  73. return PCIBIOS_BAD_REGISTER_NUMBER;
  74. data = pci_cfg_read_32bit(bus, devfn, where);
  75. if (size == 1)
  76. *val = (data >> ((where & 3) << 3)) & 0xff;
  77. else if (size == 2)
  78. *val = (data >> ((where & 3) << 3)) & 0xffff;
  79. else
  80. *val = data;
  81. return PCIBIOS_SUCCESSFUL;
  82. }
  83. static int nlm_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  84. int where, int size, u32 val)
  85. {
  86. u32 data;
  87. if ((size == 2) && (where & 1))
  88. return PCIBIOS_BAD_REGISTER_NUMBER;
  89. else if ((size == 4) && (where & 3))
  90. return PCIBIOS_BAD_REGISTER_NUMBER;
  91. data = pci_cfg_read_32bit(bus, devfn, where);
  92. if (size == 1)
  93. data = (data & ~(0xff << ((where & 3) << 3))) |
  94. (val << ((where & 3) << 3));
  95. else if (size == 2)
  96. data = (data & ~(0xffff << ((where & 3) << 3))) |
  97. (val << ((where & 3) << 3));
  98. else
  99. data = val;
  100. pci_cfg_write_32bit(bus, devfn, where, data);
  101. return PCIBIOS_SUCCESSFUL;
  102. }
  103. struct pci_ops nlm_pci_ops = {
  104. .read = nlm_pcibios_read,
  105. .write = nlm_pcibios_write
  106. };
  107. static struct resource nlm_pci_mem_resource = {
  108. .name = "XLR PCI MEM",
  109. .start = 0xd0000000UL, /* 256MB PCI mem @ 0xd000_0000 */
  110. .end = 0xdfffffffUL,
  111. .flags = IORESOURCE_MEM,
  112. };
  113. static struct resource nlm_pci_io_resource = {
  114. .name = "XLR IO MEM",
  115. .start = 0x10000000UL, /* 16MB PCI IO @ 0x1000_0000 */
  116. .end = 0x100fffffUL,
  117. .flags = IORESOURCE_IO,
  118. };
  119. struct pci_controller nlm_pci_controller = {
  120. .index = 0,
  121. .pci_ops = &nlm_pci_ops,
  122. .mem_resource = &nlm_pci_mem_resource,
  123. .mem_offset = 0x00000000UL,
  124. .io_resource = &nlm_pci_io_resource,
  125. .io_offset = 0x00000000UL,
  126. };
  127. int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  128. {
  129. if (!nlm_chip_is_xls())
  130. return PIC_PCIX_IRQ; /* for XLR just one IRQ*/
  131. /*
  132. * For XLS PCIe, there is an IRQ per Link, find out which
  133. * link the device is on to assign interrupts
  134. */
  135. if (dev->bus->self == NULL)
  136. return 0;
  137. switch (dev->bus->self->devfn) {
  138. case 0x0:
  139. return PIC_PCIE_LINK0_IRQ;
  140. case 0x8:
  141. return PIC_PCIE_LINK1_IRQ;
  142. case 0x10:
  143. if (nlm_chip_is_xls_b())
  144. return PIC_PCIE_XLSB0_LINK2_IRQ;
  145. else
  146. return PIC_PCIE_LINK2_IRQ;
  147. case 0x18:
  148. if (nlm_chip_is_xls_b())
  149. return PIC_PCIE_XLSB0_LINK3_IRQ;
  150. else
  151. return PIC_PCIE_LINK3_IRQ;
  152. }
  153. WARN(1, "Unexpected devfn %d\n", dev->bus->self->devfn);
  154. return 0;
  155. }
  156. /* Do platform specific device initialization at pci_enable_device() time */
  157. int pcibios_plat_dev_init(struct pci_dev *dev)
  158. {
  159. return 0;
  160. }
  161. static int __init pcibios_init(void)
  162. {
  163. /* PSB assigns PCI resources */
  164. pci_probe_only = 1;
  165. pci_config_base = ioremap(DEFAULT_PCI_CONFIG_BASE, 16 << 20);
  166. /* Extend IO port for memory mapped io */
  167. ioport_resource.start = 0;
  168. ioport_resource.end = ~0;
  169. set_io_port_base(CKSEG1);
  170. nlm_pci_controller.io_map_base = CKSEG1;
  171. pr_info("Registering XLR/XLS PCIX/PCIE Controller.\n");
  172. register_pci_controller(&nlm_pci_controller);
  173. return 0;
  174. }
  175. arch_initcall(pcibios_init);
  176. struct pci_fixup pcibios_fixups[] = {
  177. {0}
  178. };