ops-tx4938.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Define the pci_ops for the Toshiba rbtx4938
  3. * Copyright (C) 2000-2001 Toshiba Corporation
  4. *
  5. * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
  6. * terms of the GNU General Public License version 2. This program is
  7. * licensed "as is" without any warranty of any kind, whether express
  8. * or implied.
  9. *
  10. * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
  11. */
  12. #include <linux/types.h>
  13. #include <linux/pci.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <asm/addrspace.h>
  17. #include <asm/tx4938/rbtx4938.h>
  18. /* initialize in setup */
  19. struct resource pci_io_resource = {
  20. .name = "pci IO space",
  21. .start = 0,
  22. .end = 0,
  23. .flags = IORESOURCE_IO
  24. };
  25. /* initialize in setup */
  26. struct resource pci_mem_resource = {
  27. .name = "pci memory space",
  28. .start = 0,
  29. .end = 0,
  30. .flags = IORESOURCE_MEM
  31. };
  32. struct resource tx4938_pcic1_pci_io_resource = {
  33. .name = "PCI1 IO",
  34. .start = 0,
  35. .end = 0,
  36. .flags = IORESOURCE_IO
  37. };
  38. struct resource tx4938_pcic1_pci_mem_resource = {
  39. .name = "PCI1 mem",
  40. .start = 0,
  41. .end = 0,
  42. .flags = IORESOURCE_MEM
  43. };
  44. static int mkaddr(int bus, int dev_fn, int where,
  45. struct tx4938_pcic_reg *pcicptr)
  46. {
  47. if (bus > 0) {
  48. /* Type 1 configuration */
  49. pcicptr->g2pcfgadrs = ((bus & 0xff) << 0x10) |
  50. ((dev_fn & 0xff) << 0x08) | (where & 0xfc) | 1;
  51. } else {
  52. if (dev_fn >= PCI_DEVFN(TX4938_PCIC_MAX_DEVNU, 0))
  53. return -1;
  54. /* Type 0 configuration */
  55. pcicptr->g2pcfgadrs = ((bus & 0xff) << 0x10) |
  56. ((dev_fn & 0xff) << 0x08) | (where & 0xfc);
  57. }
  58. /* clear M_ABORT and Disable M_ABORT Int. */
  59. pcicptr->pcistatus =
  60. (pcicptr->pcistatus & 0x0000ffff) |
  61. (PCI_STATUS_REC_MASTER_ABORT << 16);
  62. pcicptr->pcimask &= ~PCI_STATUS_REC_MASTER_ABORT;
  63. return 0;
  64. }
  65. static int check_abort(struct tx4938_pcic_reg *pcicptr)
  66. {
  67. int code = PCIBIOS_SUCCESSFUL;
  68. /* wait write cycle completion before checking error status */
  69. while (pcicptr->pcicstatus & TX4938_PCIC_PCICSTATUS_IWB)
  70. ;
  71. if (pcicptr->pcistatus & (PCI_STATUS_REC_MASTER_ABORT << 16)) {
  72. pcicptr->pcistatus =
  73. (pcicptr->
  74. pcistatus & 0x0000ffff) | (PCI_STATUS_REC_MASTER_ABORT
  75. << 16);
  76. pcicptr->pcimask |= PCI_STATUS_REC_MASTER_ABORT;
  77. code = PCIBIOS_DEVICE_NOT_FOUND;
  78. }
  79. return code;
  80. }
  81. extern struct pci_controller tx4938_pci_controller[];
  82. extern struct tx4938_pcic_reg *get_tx4938_pcicptr(int ch);
  83. static struct tx4938_pcic_reg *pci_bus_to_pcicptr(struct pci_bus *bus)
  84. {
  85. struct pci_controller *channel = bus->sysdata;
  86. return get_tx4938_pcicptr(channel - &tx4938_pci_controller[0]);
  87. }
  88. static int tx4938_pcibios_read_config(struct pci_bus *bus, unsigned int devfn,
  89. int where, int size, u32 * val)
  90. {
  91. int retval, dev, busno, func;
  92. struct tx4938_pcic_reg *pcicptr = pci_bus_to_pcicptr(bus);
  93. void __iomem *cfgdata =
  94. (void __iomem *)(unsigned long)&pcicptr->g2pcfgdata;
  95. dev = PCI_SLOT(devfn);
  96. func = PCI_FUNC(devfn);
  97. /* check if the bus is top-level */
  98. if (bus->parent != NULL)
  99. busno = bus->number;
  100. else {
  101. busno = 0;
  102. }
  103. if (mkaddr(busno, devfn, where, pcicptr))
  104. return -1;
  105. switch (size) {
  106. case 1:
  107. #ifdef __BIG_ENDIAN
  108. cfgdata += (where & 3) ^ 3;
  109. #else
  110. cfgdata += where & 3;
  111. #endif
  112. *val = __raw_readb(cfgdata);
  113. break;
  114. case 2:
  115. #ifdef __BIG_ENDIAN
  116. cfgdata += (where & 2) ^ 2;
  117. #else
  118. cfgdata += where & 2;
  119. #endif
  120. *val = __raw_readw(cfgdata);
  121. break;
  122. case 4:
  123. *val = __raw_readl(cfgdata);
  124. break;
  125. }
  126. retval = check_abort(pcicptr);
  127. if (retval == PCIBIOS_DEVICE_NOT_FOUND)
  128. *val = 0xffffffff;
  129. return retval;
  130. }
  131. static int tx4938_pcibios_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  132. int size, u32 val)
  133. {
  134. int dev, busno, func;
  135. struct tx4938_pcic_reg *pcicptr = pci_bus_to_pcicptr(bus);
  136. void __iomem *cfgdata =
  137. (void __iomem *)(unsigned long)&pcicptr->g2pcfgdata;
  138. busno = bus->number;
  139. dev = PCI_SLOT(devfn);
  140. func = PCI_FUNC(devfn);
  141. /* check if the bus is top-level */
  142. if (bus->parent != NULL) {
  143. busno = bus->number;
  144. } else {
  145. busno = 0;
  146. }
  147. if (mkaddr(busno, devfn, where, pcicptr))
  148. return -1;
  149. switch (size) {
  150. case 1:
  151. #ifdef __BIG_ENDIAN
  152. cfgdata += (where & 3) ^ 3;
  153. #else
  154. cfgdata += where & 3;
  155. #endif
  156. __raw_writeb(val, cfgdata);
  157. break;
  158. case 2:
  159. #ifdef __BIG_ENDIAN
  160. cfgdata += (where & 2) ^ 2;
  161. #else
  162. cfgdata += where & 2;
  163. #endif
  164. __raw_writew(val, cfgdata);
  165. break;
  166. case 4:
  167. __raw_writel(val, cfgdata);
  168. break;
  169. }
  170. return check_abort(pcicptr);
  171. }
  172. struct pci_ops tx4938_pci_ops = {
  173. tx4938_pcibios_read_config,
  174. tx4938_pcibios_write_config
  175. };
  176. struct pci_controller tx4938_pci_controller[] = {
  177. /* h/w only supports devices 0x00 to 0x14 */
  178. {
  179. .pci_ops = &tx4938_pci_ops,
  180. .io_resource = &pci_io_resource,
  181. .mem_resource = &pci_mem_resource,
  182. },
  183. /* h/w only supports devices 0x00 to 0x14 */
  184. {
  185. .pci_ops = &tx4938_pci_ops,
  186. .io_resource = &tx4938_pcic1_pci_io_resource,
  187. .mem_resource = &tx4938_pcic1_pci_mem_resource,
  188. }
  189. };