pci-nanoengine.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * linux/arch/arm/mach-sa1100/pci-nanoengine.c
  3. *
  4. * PCI functions for BSE nanoEngine PCI
  5. *
  6. * Copyright (C) 2010 Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/irq.h>
  24. #include <linux/pci.h>
  25. #include <asm/mach/pci.h>
  26. #include <asm/mach-types.h>
  27. #include <mach/nanoengine.h>
  28. #include <mach/hardware.h>
  29. static void __iomem *nanoengine_pci_map_bus(struct pci_bus *bus,
  30. unsigned int devfn, int where)
  31. {
  32. if (bus->number != 0 || (devfn >> 3) != 0)
  33. return NULL;
  34. return (void __iomem *)NANO_PCI_CONFIG_SPACE_VIRT +
  35. ((bus->number << 16) | (devfn << 8) | (where & ~3));
  36. }
  37. static struct pci_ops pci_nano_ops = {
  38. .map_bus = nanoengine_pci_map_bus,
  39. .read = pci_generic_config_read32,
  40. .write = pci_generic_config_write32,
  41. };
  42. static int __init pci_nanoengine_map_irq(const struct pci_dev *dev, u8 slot,
  43. u8 pin)
  44. {
  45. return NANOENGINE_IRQ_GPIO_PCI;
  46. }
  47. static struct resource pci_io_ports =
  48. DEFINE_RES_IO_NAMED(0x400, 0x400, "PCI IO");
  49. static struct resource pci_non_prefetchable_memory = {
  50. .name = "PCI non-prefetchable",
  51. .start = NANO_PCI_MEM_RW_PHYS,
  52. /* nanoEngine documentation says there is a 1 Megabyte window here,
  53. * but PCI reports just 128 + 8 kbytes. */
  54. .end = NANO_PCI_MEM_RW_PHYS + NANO_PCI_MEM_RW_SIZE - 1,
  55. /* .end = NANO_PCI_MEM_RW_PHYS + SZ_128K + SZ_8K - 1,*/
  56. .flags = IORESOURCE_MEM,
  57. };
  58. /*
  59. * nanoEngine PCI reports 1 Megabyte of prefetchable memory, but it
  60. * overlaps with previously defined memory.
  61. *
  62. * Here is what happens:
  63. *
  64. # dmesg
  65. ...
  66. pci 0000:00:00.0: [8086:1209] type 0 class 0x000200
  67. pci 0000:00:00.0: reg 10: [mem 0x00021000-0x00021fff]
  68. pci 0000:00:00.0: reg 14: [io 0x0000-0x003f]
  69. pci 0000:00:00.0: reg 18: [mem 0x00000000-0x0001ffff]
  70. pci 0000:00:00.0: reg 30: [mem 0x00000000-0x000fffff pref]
  71. pci 0000:00:00.0: supports D1 D2
  72. pci 0000:00:00.0: PME# supported from D0 D1 D2 D3hot
  73. pci 0000:00:00.0: PME# disabled
  74. PCI: bus0: Fast back to back transfers enabled
  75. pci 0000:00:00.0: BAR 6: can't assign mem pref (size 0x100000)
  76. pci 0000:00:00.0: BAR 2: assigned [mem 0x18600000-0x1861ffff]
  77. pci 0000:00:00.0: BAR 2: set to [mem 0x18600000-0x1861ffff] (PCI address [0x0-0x1ffff])
  78. pci 0000:00:00.0: BAR 0: assigned [mem 0x18620000-0x18620fff]
  79. pci 0000:00:00.0: BAR 0: set to [mem 0x18620000-0x18620fff] (PCI address [0x20000-0x20fff])
  80. pci 0000:00:00.0: BAR 1: assigned [io 0x0400-0x043f]
  81. pci 0000:00:00.0: BAR 1: set to [io 0x0400-0x043f] (PCI address [0x0-0x3f])
  82. *
  83. * On the other hand, if we do not request the prefetchable memory resource,
  84. * linux will alloc it first and the two non-prefetchable memory areas that
  85. * are our real interest will not be mapped. So we choose to map it to an
  86. * unused area. It gets recognized as expansion ROM, but becomes disabled.
  87. *
  88. * Here is what happens then:
  89. *
  90. # dmesg
  91. ...
  92. pci 0000:00:00.0: [8086:1209] type 0 class 0x000200
  93. pci 0000:00:00.0: reg 10: [mem 0x00021000-0x00021fff]
  94. pci 0000:00:00.0: reg 14: [io 0x0000-0x003f]
  95. pci 0000:00:00.0: reg 18: [mem 0x00000000-0x0001ffff]
  96. pci 0000:00:00.0: reg 30: [mem 0x00000000-0x000fffff pref]
  97. pci 0000:00:00.0: supports D1 D2
  98. pci 0000:00:00.0: PME# supported from D0 D1 D2 D3hot
  99. pci 0000:00:00.0: PME# disabled
  100. PCI: bus0: Fast back to back transfers enabled
  101. pci 0000:00:00.0: BAR 6: assigned [mem 0x78000000-0x780fffff pref]
  102. pci 0000:00:00.0: BAR 2: assigned [mem 0x18600000-0x1861ffff]
  103. pci 0000:00:00.0: BAR 2: set to [mem 0x18600000-0x1861ffff] (PCI address [0x0-0x1ffff])
  104. pci 0000:00:00.0: BAR 0: assigned [mem 0x18620000-0x18620fff]
  105. pci 0000:00:00.0: BAR 0: set to [mem 0x18620000-0x18620fff] (PCI address [0x20000-0x20fff])
  106. pci 0000:00:00.0: BAR 1: assigned [io 0x0400-0x043f]
  107. pci 0000:00:00.0: BAR 1: set to [io 0x0400-0x043f] (PCI address [0x0-0x3f])
  108. # lspci -vv -s 0000:00:00.0
  109. 00:00.0 Class 0200: Device 8086:1209 (rev 09)
  110. Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr+ Stepping- SERR+ FastB2B- DisINTx-
  111. Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR+ <PERR+ INTx-
  112. Latency: 0 (2000ns min, 14000ns max), Cache Line Size: 32 bytes
  113. Interrupt: pin A routed to IRQ 0
  114. Region 0: Memory at 18620000 (32-bit, non-prefetchable) [size=4K]
  115. Region 1: I/O ports at 0400 [size=64]
  116. Region 2: [virtual] Memory at 18600000 (32-bit, non-prefetchable) [size=128K]
  117. [virtual] Expansion ROM at 78000000 [disabled] [size=1M]
  118. Capabilities: [dc] Power Management version 2
  119. Flags: PMEClk- DSI+ D1+ D2+ AuxCurrent=0mA PME(D0+,D1+,D2+,D3hot+,D3cold-)
  120. Status: D0 NoSoftRst- PME-Enable- DSel=0 DScale=2 PME-
  121. Kernel driver in use: e100
  122. Kernel modules: e100
  123. *
  124. */
  125. static struct resource pci_prefetchable_memory = {
  126. .name = "PCI prefetchable",
  127. .start = 0x78000000,
  128. .end = 0x78000000 + NANO_PCI_MEM_RW_SIZE - 1,
  129. .flags = IORESOURCE_MEM | IORESOURCE_PREFETCH,
  130. };
  131. static int __init pci_nanoengine_setup_resources(struct pci_sys_data *sys)
  132. {
  133. if (request_resource(&ioport_resource, &pci_io_ports)) {
  134. printk(KERN_ERR "PCI: unable to allocate io port region\n");
  135. return -EBUSY;
  136. }
  137. if (request_resource(&iomem_resource, &pci_non_prefetchable_memory)) {
  138. release_resource(&pci_io_ports);
  139. printk(KERN_ERR "PCI: unable to allocate non prefetchable\n");
  140. return -EBUSY;
  141. }
  142. if (request_resource(&iomem_resource, &pci_prefetchable_memory)) {
  143. release_resource(&pci_io_ports);
  144. release_resource(&pci_non_prefetchable_memory);
  145. printk(KERN_ERR "PCI: unable to allocate prefetchable\n");
  146. return -EBUSY;
  147. }
  148. pci_add_resource_offset(&sys->resources, &pci_io_ports, sys->io_offset);
  149. pci_add_resource_offset(&sys->resources,
  150. &pci_non_prefetchable_memory, sys->mem_offset);
  151. pci_add_resource_offset(&sys->resources,
  152. &pci_prefetchable_memory, sys->mem_offset);
  153. return 1;
  154. }
  155. int __init pci_nanoengine_setup(int nr, struct pci_sys_data *sys)
  156. {
  157. int ret = 0;
  158. pcibios_min_io = 0;
  159. pcibios_min_mem = 0;
  160. if (nr == 0) {
  161. sys->mem_offset = NANO_PCI_MEM_RW_PHYS;
  162. sys->io_offset = 0x400;
  163. ret = pci_nanoengine_setup_resources(sys);
  164. /* Enable alternate memory bus master mode, see
  165. * "Intel StrongARM SA1110 Developer's Manual",
  166. * section 10.8, "Alternate Memory Bus Master Mode". */
  167. GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
  168. GAFR |= GPIO_MBGNT | GPIO_MBREQ;
  169. TUCR |= TUCR_MBGPIO;
  170. }
  171. return ret;
  172. }
  173. static struct hw_pci nanoengine_pci __initdata = {
  174. .map_irq = pci_nanoengine_map_irq,
  175. .nr_controllers = 1,
  176. .ops = &pci_nano_ops,
  177. .setup = pci_nanoengine_setup,
  178. };
  179. static int __init nanoengine_pci_init(void)
  180. {
  181. if (machine_is_nanoengine())
  182. pci_common_init(&nanoengine_pci);
  183. return 0;
  184. }
  185. subsys_initcall(nanoengine_pci_init);