pci-nanoengine.c 6.6 KB

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