ops-tx3927.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: MontaVista Software, Inc.
  4. * ahennessy@mvista.com
  5. *
  6. * Copyright (C) 2000-2001 Toshiba Corporation
  7. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  8. *
  9. * Based on arch/mips/ddb5xxx/ddb5477/pci_ops.c
  10. *
  11. * Define the pci_ops for TX3927.
  12. *
  13. * Much of the code is derived from the original DDB5074 port by
  14. * Geert Uytterhoeven <geert@linux-m68k.org>
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the
  18. * Free Software Foundation; either version 2 of the License, or (at your
  19. * option) any later version.
  20. *
  21. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  22. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  23. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  24. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  27. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  28. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * You should have received a copy of the GNU General Public License along
  33. * with this program; if not, write to the Free Software Foundation, Inc.,
  34. * 675 Mass Ave, Cambridge, MA 02139, USA.
  35. */
  36. #include <linux/types.h>
  37. #include <linux/pci.h>
  38. #include <linux/kernel.h>
  39. #include <linux/init.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/irq.h>
  42. #include <asm/addrspace.h>
  43. #include <asm/txx9irq.h>
  44. #include <asm/txx9/pci.h>
  45. #include <asm/txx9/tx3927.h>
  46. static int mkaddr(struct pci_bus *bus, unsigned char devfn, unsigned char where)
  47. {
  48. if (bus->parent == NULL &&
  49. devfn >= PCI_DEVFN(TX3927_PCIC_MAX_DEVNU, 0))
  50. return -1;
  51. tx3927_pcicptr->ica =
  52. ((bus->number & 0xff) << 0x10) |
  53. ((devfn & 0xff) << 0x08) |
  54. (where & 0xfc) | (bus->parent ? 1 : 0);
  55. /* clear M_ABORT and Disable M_ABORT Int. */
  56. tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
  57. tx3927_pcicptr->pcistatim &= ~PCI_STATUS_REC_MASTER_ABORT;
  58. return 0;
  59. }
  60. static inline int check_abort(void)
  61. {
  62. if (tx3927_pcicptr->pcistat & PCI_STATUS_REC_MASTER_ABORT) {
  63. tx3927_pcicptr->pcistat |= PCI_STATUS_REC_MASTER_ABORT;
  64. tx3927_pcicptr->pcistatim |= PCI_STATUS_REC_MASTER_ABORT;
  65. /* flush write buffer */
  66. iob();
  67. return PCIBIOS_DEVICE_NOT_FOUND;
  68. }
  69. return PCIBIOS_SUCCESSFUL;
  70. }
  71. static int tx3927_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  72. int where, int size, u32 * val)
  73. {
  74. if (mkaddr(bus, devfn, where)) {
  75. *val = 0xffffffff;
  76. return PCIBIOS_DEVICE_NOT_FOUND;
  77. }
  78. switch (size) {
  79. case 1:
  80. *val = *(volatile u8 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3));
  81. break;
  82. case 2:
  83. *val = le16_to_cpu(*(volatile u16 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3)));
  84. break;
  85. case 4:
  86. *val = le32_to_cpu(tx3927_pcicptr->icd);
  87. break;
  88. }
  89. return check_abort();
  90. }
  91. static int tx3927_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  92. int where, int size, u32 val)
  93. {
  94. if (mkaddr(bus, devfn, where))
  95. return PCIBIOS_DEVICE_NOT_FOUND;
  96. switch (size) {
  97. case 1:
  98. *(volatile u8 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 3)) = val;
  99. break;
  100. case 2:
  101. *(volatile u16 *) ((unsigned long) & tx3927_pcicptr->icd | (where & 2)) =
  102. cpu_to_le16(val);
  103. break;
  104. case 4:
  105. tx3927_pcicptr->icd = cpu_to_le32(val);
  106. }
  107. return check_abort();
  108. }
  109. static struct pci_ops tx3927_pci_ops = {
  110. .read = tx3927_pci_read_config,
  111. .write = tx3927_pci_write_config,
  112. };
  113. void __init tx3927_pcic_setup(struct pci_controller *channel,
  114. unsigned long sdram_size, int extarb)
  115. {
  116. unsigned long flags;
  117. unsigned long io_base =
  118. channel->io_resource->start + mips_io_port_base - IO_BASE;
  119. unsigned long io_size =
  120. channel->io_resource->end - channel->io_resource->start;
  121. unsigned long io_pciaddr =
  122. channel->io_resource->start - channel->io_offset;
  123. unsigned long mem_base =
  124. channel->mem_resource->start;
  125. unsigned long mem_size =
  126. channel->mem_resource->end - channel->mem_resource->start;
  127. unsigned long mem_pciaddr =
  128. channel->mem_resource->start - channel->mem_offset;
  129. printk(KERN_INFO "TX3927 PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s",
  130. tx3927_pcicptr->did, tx3927_pcicptr->vid,
  131. tx3927_pcicptr->rid,
  132. extarb ? "External" : "Internal");
  133. channel->pci_ops = &tx3927_pci_ops;
  134. local_irq_save(flags);
  135. /* Disable External PCI Config. Access */
  136. tx3927_pcicptr->lbc = TX3927_PCIC_LBC_EPCAD;
  137. #ifdef __BIG_ENDIAN
  138. tx3927_pcicptr->lbc |= TX3927_PCIC_LBC_IBSE |
  139. TX3927_PCIC_LBC_TIBSE |
  140. TX3927_PCIC_LBC_TMFBSE | TX3927_PCIC_LBC_MSDSE;
  141. #endif
  142. /* LB->PCI mappings */
  143. tx3927_pcicptr->iomas = ~(io_size - 1);
  144. tx3927_pcicptr->ilbioma = io_base;
  145. tx3927_pcicptr->ipbioma = io_pciaddr;
  146. tx3927_pcicptr->mmas = ~(mem_size - 1);
  147. tx3927_pcicptr->ilbmma = mem_base;
  148. tx3927_pcicptr->ipbmma = mem_pciaddr;
  149. /* PCI->LB mappings */
  150. tx3927_pcicptr->iobas = 0xffffffff;
  151. tx3927_pcicptr->ioba = 0;
  152. tx3927_pcicptr->tlbioma = 0;
  153. tx3927_pcicptr->mbas = ~(sdram_size - 1);
  154. tx3927_pcicptr->mba = 0;
  155. tx3927_pcicptr->tlbmma = 0;
  156. /* Enable Direct mapping Address Space Decoder */
  157. tx3927_pcicptr->lbc |= TX3927_PCIC_LBC_ILMDE | TX3927_PCIC_LBC_ILIDE;
  158. /* Clear All Local Bus Status */
  159. tx3927_pcicptr->lbstat = TX3927_PCIC_LBIM_ALL;
  160. /* Enable All Local Bus Interrupts */
  161. tx3927_pcicptr->lbim = TX3927_PCIC_LBIM_ALL;
  162. /* Clear All PCI Status Error */
  163. tx3927_pcicptr->pcistat = TX3927_PCIC_PCISTATIM_ALL;
  164. /* Enable All PCI Status Error Interrupts */
  165. tx3927_pcicptr->pcistatim = TX3927_PCIC_PCISTATIM_ALL;
  166. /* PCIC Int => IRC IRQ10 */
  167. tx3927_pcicptr->il = TX3927_IR_PCI;
  168. /* Target Control (per errata) */
  169. tx3927_pcicptr->tc = TX3927_PCIC_TC_OF8E | TX3927_PCIC_TC_IF8E;
  170. /* Enable Bus Arbiter */
  171. if (!extarb)
  172. tx3927_pcicptr->pbapmc = TX3927_PCIC_PBAPMC_PBAEN;
  173. tx3927_pcicptr->pcicmd = PCI_COMMAND_MASTER |
  174. PCI_COMMAND_MEMORY |
  175. PCI_COMMAND_IO |
  176. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  177. local_irq_restore(flags);
  178. }
  179. static irqreturn_t tx3927_pcierr_interrupt(int irq, void *dev_id)
  180. {
  181. struct pt_regs *regs = get_irq_regs();
  182. if (txx9_pci_err_action != TXX9_PCI_ERR_IGNORE) {
  183. printk(KERN_WARNING "PCI error interrupt at 0x%08lx.\n",
  184. regs->cp0_epc);
  185. printk(KERN_WARNING "pcistat:%02x, lbstat:%04lx\n",
  186. tx3927_pcicptr->pcistat, tx3927_pcicptr->lbstat);
  187. }
  188. if (txx9_pci_err_action != TXX9_PCI_ERR_PANIC) {
  189. /* clear all pci errors */
  190. tx3927_pcicptr->pcistat |= TX3927_PCIC_PCISTATIM_ALL;
  191. tx3927_pcicptr->istat = TX3927_PCIC_IIM_ALL;
  192. tx3927_pcicptr->tstat = TX3927_PCIC_TIM_ALL;
  193. tx3927_pcicptr->lbstat = TX3927_PCIC_LBIM_ALL;
  194. return IRQ_HANDLED;
  195. }
  196. console_verbose();
  197. panic("PCI error.");
  198. }
  199. void __init tx3927_setup_pcierr_irq(void)
  200. {
  201. if (request_irq(TXX9_IRQ_BASE + TX3927_IR_PCI,
  202. tx3927_pcierr_interrupt,
  203. 0, "PCI error",
  204. (void *)TX3927_PCIC_REG))
  205. printk(KERN_WARNING "Failed to request irq for PCIERR\n");
  206. }