ops-emma2rh.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * arch/mips/pci/ops-emma2rh.c
  3. * This file defines the PCI operation for EMMA2RH.
  4. *
  5. * Copyright (C) NEC Electronics Corporation 2004-2006
  6. *
  7. * This file is based on the arch/mips/pci/ops-vr41xx.c
  8. *
  9. * Copyright 2001 MontaVista Software Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #include <linux/pci.h>
  26. #include <linux/kernel.h>
  27. #include <linux/types.h>
  28. #include <asm/addrspace.h>
  29. #include <asm/debug.h>
  30. #include <asm/emma/emma2rh.h>
  31. #define RTABORT (0x1<<9)
  32. #define RMABORT (0x1<<10)
  33. #define EMMA2RH_PCI_SLOT_NUM 9 /* 0000:09.0 is final PCI device */
  34. /*
  35. * access config space
  36. */
  37. static int check_args(struct pci_bus *bus, u32 devfn, u32 * bus_num)
  38. {
  39. /* check if the bus is top-level */
  40. if (bus->parent != NULL) {
  41. *bus_num = bus->number;
  42. db_assert(bus_num != NULL);
  43. } else
  44. *bus_num = 0;
  45. if (*bus_num == 0) {
  46. /* Type 0 */
  47. if (PCI_SLOT(devfn) >= 10)
  48. return PCIBIOS_DEVICE_NOT_FOUND;
  49. } else {
  50. /* Type 1 */
  51. if ((*bus_num >= 64) || (PCI_SLOT(devfn) >= 16))
  52. return PCIBIOS_DEVICE_NOT_FOUND;
  53. }
  54. return 0;
  55. }
  56. static inline int set_pci_configuration_address(unsigned char bus_num,
  57. unsigned int devfn, int where)
  58. {
  59. u32 config_win0;
  60. emma2rh_out32(EMMA2RH_PCI_INT, ~RMABORT);
  61. if (bus_num == 0)
  62. /*
  63. * Type 0 configuration
  64. */
  65. config_win0 = (1 << (22 + PCI_SLOT(devfn))) | (5 << 9);
  66. else
  67. /*
  68. * Type 1 configuration
  69. */
  70. config_win0 = (bus_num << 26) | (PCI_SLOT(devfn) << 22) |
  71. (1 << 15) | (5 << 9);
  72. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, config_win0);
  73. return 0;
  74. }
  75. static int pci_config_read(struct pci_bus *bus, unsigned int devfn, int where,
  76. int size, uint32_t * val)
  77. {
  78. u32 bus_num;
  79. u32 base = KSEG1ADDR(EMMA2RH_PCI_CONFIG_BASE);
  80. u32 backup_win0;
  81. u32 data;
  82. *val = 0xffffffffU;
  83. if (check_args(bus, devfn, &bus_num) == PCIBIOS_DEVICE_NOT_FOUND)
  84. return PCIBIOS_DEVICE_NOT_FOUND;
  85. backup_win0 = emma2rh_in32(EMMA2RH_PCI_IWIN0_CTR);
  86. if (set_pci_configuration_address(bus_num, devfn, where) < 0)
  87. return PCIBIOS_DEVICE_NOT_FOUND;
  88. data =
  89. *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
  90. (where & 0xfffffffc));
  91. switch (size) {
  92. case 1:
  93. *val = (data >> ((where & 3) << 3)) & 0xffU;
  94. break;
  95. case 2:
  96. *val = (data >> ((where & 2) << 3)) & 0xffffU;
  97. break;
  98. case 4:
  99. *val = data;
  100. break;
  101. default:
  102. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  103. return PCIBIOS_FUNC_NOT_SUPPORTED;
  104. }
  105. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  106. if (emma2rh_in32(EMMA2RH_PCI_INT) & RMABORT)
  107. return PCIBIOS_DEVICE_NOT_FOUND;
  108. return PCIBIOS_SUCCESSFUL;
  109. }
  110. static int pci_config_write(struct pci_bus *bus, unsigned int devfn, int where,
  111. int size, u32 val)
  112. {
  113. u32 bus_num;
  114. u32 base = KSEG1ADDR(EMMA2RH_PCI_CONFIG_BASE);
  115. u32 backup_win0;
  116. u32 data;
  117. int shift;
  118. if (check_args(bus, devfn, &bus_num) == PCIBIOS_DEVICE_NOT_FOUND)
  119. return PCIBIOS_DEVICE_NOT_FOUND;
  120. backup_win0 = emma2rh_in32(EMMA2RH_PCI_IWIN0_CTR);
  121. if (set_pci_configuration_address(bus_num, devfn, where) < 0)
  122. return PCIBIOS_DEVICE_NOT_FOUND;
  123. /* read modify write */
  124. data =
  125. *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
  126. (where & 0xfffffffc));
  127. switch (size) {
  128. case 1:
  129. shift = (where & 3) << 3;
  130. data &= ~(0xffU << shift);
  131. data |= ((val & 0xffU) << shift);
  132. break;
  133. case 2:
  134. shift = (where & 2) << 3;
  135. data &= ~(0xffffU << shift);
  136. data |= ((val & 0xffffU) << shift);
  137. break;
  138. case 4:
  139. data = val;
  140. break;
  141. default:
  142. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  143. return PCIBIOS_FUNC_NOT_SUPPORTED;
  144. }
  145. *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
  146. (where & 0xfffffffc)) = data;
  147. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  148. if (emma2rh_in32(EMMA2RH_PCI_INT) & RMABORT)
  149. return PCIBIOS_DEVICE_NOT_FOUND;
  150. return PCIBIOS_SUCCESSFUL;
  151. }
  152. struct pci_ops emma2rh_pci_ops = {
  153. .read = pci_config_read,
  154. .write = pci_config_write,
  155. };