ops-emma2rh.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/config.h>
  26. #include <linux/pci.h>
  27. #include <linux/kernel.h>
  28. #include <linux/types.h>
  29. #include <asm/addrspace.h>
  30. #include <asm/debug.h>
  31. #include <asm/emma2rh/emma2rh.h>
  32. #define RTABORT (0x1<<9)
  33. #define RMABORT (0x1<<10)
  34. #define EMMA2RH_PCI_SLOT_NUM 9 /* 0000:09.0 is final PCI device */
  35. /*
  36. * access config space
  37. */
  38. static int check_args(struct pci_bus *bus, u32 devfn, u32 * bus_num)
  39. {
  40. /* check if the bus is top-level */
  41. if (bus->parent != NULL) {
  42. *bus_num = bus->number;
  43. db_assert(bus_num != 0);
  44. } else
  45. *bus_num = 0;
  46. if (*bus_num == 0) {
  47. /* Type 0 */
  48. if (PCI_SLOT(devfn) >= 10)
  49. return PCIBIOS_DEVICE_NOT_FOUND;
  50. } else {
  51. /* Type 1 */
  52. if ((*bus_num >= 64) || (PCI_SLOT(devfn) >= 16))
  53. return PCIBIOS_DEVICE_NOT_FOUND;
  54. }
  55. return 0;
  56. }
  57. static inline int set_pci_configuration_address(unsigned char bus_num,
  58. unsigned int devfn, int where)
  59. {
  60. u32 config_win0;
  61. emma2rh_out32(EMMA2RH_PCI_INT, ~RMABORT);
  62. if (bus_num == 0)
  63. /*
  64. * Type 0 configuration
  65. */
  66. config_win0 = (1 << (22 + PCI_SLOT(devfn))) | (5 << 9);
  67. else
  68. /*
  69. * Type 1 configuration
  70. */
  71. config_win0 = (bus_num << 26) | (PCI_SLOT(devfn) << 22) |
  72. (1 << 15) | (5 << 9);
  73. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, config_win0);
  74. return 0;
  75. }
  76. static int pci_config_read(struct pci_bus *bus, unsigned int devfn, int where,
  77. int size, uint32_t * val)
  78. {
  79. u32 bus_num;
  80. u32 base = KSEG1ADDR(EMMA2RH_PCI_CONFIG_BASE);
  81. u32 backup_win0;
  82. u32 data;
  83. *val = 0xffffffffU;
  84. if (check_args(bus, devfn, &bus_num) == PCIBIOS_DEVICE_NOT_FOUND)
  85. return PCIBIOS_DEVICE_NOT_FOUND;
  86. backup_win0 = emma2rh_in32(EMMA2RH_PCI_IWIN0_CTR);
  87. if (set_pci_configuration_address(bus_num, devfn, where) < 0)
  88. return PCIBIOS_DEVICE_NOT_FOUND;
  89. data =
  90. *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
  91. (where & 0xfffffffc));
  92. switch (size) {
  93. case 1:
  94. *val = (data >> ((where & 3) << 3)) & 0xffU;
  95. break;
  96. case 2:
  97. *val = (data >> ((where & 2) << 3)) & 0xffffU;
  98. break;
  99. case 4:
  100. *val = data;
  101. break;
  102. default:
  103. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  104. return PCIBIOS_FUNC_NOT_SUPPORTED;
  105. }
  106. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  107. if (emma2rh_in32(EMMA2RH_PCI_INT) & RMABORT)
  108. return PCIBIOS_DEVICE_NOT_FOUND;
  109. return PCIBIOS_SUCCESSFUL;
  110. }
  111. static int pci_config_write(struct pci_bus *bus, unsigned int devfn, int where,
  112. int size, u32 val)
  113. {
  114. u32 bus_num;
  115. u32 base = KSEG1ADDR(EMMA2RH_PCI_CONFIG_BASE);
  116. u32 backup_win0;
  117. u32 data;
  118. int shift;
  119. if (check_args(bus, devfn, &bus_num) == PCIBIOS_DEVICE_NOT_FOUND)
  120. return PCIBIOS_DEVICE_NOT_FOUND;
  121. backup_win0 = emma2rh_in32(EMMA2RH_PCI_IWIN0_CTR);
  122. if (set_pci_configuration_address(bus_num, devfn, where) < 0)
  123. return PCIBIOS_DEVICE_NOT_FOUND;
  124. /* read modify write */
  125. data =
  126. *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
  127. (where & 0xfffffffc));
  128. switch (size) {
  129. case 1:
  130. shift = (where & 3) << 3;
  131. data &= ~(0xffU << shift);
  132. data |= ((val & 0xffU) << shift);
  133. break;
  134. case 2:
  135. shift = (where & 2) << 3;
  136. data &= ~(0xffffU << shift);
  137. data |= ((val & 0xffffU) << shift);
  138. break;
  139. case 4:
  140. data = val;
  141. break;
  142. default:
  143. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  144. return PCIBIOS_FUNC_NOT_SUPPORTED;
  145. }
  146. *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
  147. (where & 0xfffffffc)) = data;
  148. emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
  149. if (emma2rh_in32(EMMA2RH_PCI_INT) & RMABORT)
  150. return PCIBIOS_DEVICE_NOT_FOUND;
  151. return PCIBIOS_SUCCESSFUL;
  152. }
  153. struct pci_ops emma2rh_pci_ops = {
  154. .read = pci_config_read,
  155. .write = pci_config_write,
  156. };