ops-gt64120.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 1999, 2000 MIPS Technologies, Inc. All rights reserved.
  4. *
  5. * This program is free software; you can distribute it and/or modify it
  6. * under the terms of the GNU General Public License (Version 2) as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  17. */
  18. #include <linux/types.h>
  19. #include <linux/pci.h>
  20. #include <linux/kernel.h>
  21. #include <asm/gt64120.h>
  22. #define PCI_ACCESS_READ 0
  23. #define PCI_ACCESS_WRITE 1
  24. /*
  25. * PCI configuration cycle AD bus definition
  26. */
  27. /* Type 0 */
  28. #define PCI_CFG_TYPE0_REG_SHF 0
  29. #define PCI_CFG_TYPE0_FUNC_SHF 8
  30. /* Type 1 */
  31. #define PCI_CFG_TYPE1_REG_SHF 0
  32. #define PCI_CFG_TYPE1_FUNC_SHF 8
  33. #define PCI_CFG_TYPE1_DEV_SHF 11
  34. #define PCI_CFG_TYPE1_BUS_SHF 16
  35. static int gt64120_pcibios_config_access(unsigned char access_type,
  36. struct pci_bus *bus, unsigned int devfn, int where, u32 * data)
  37. {
  38. unsigned char busnum = bus->number;
  39. u32 intr;
  40. if ((busnum == 0) && (PCI_SLOT(devfn) == 0))
  41. /* Galileo itself is devfn 0, don't move it around */
  42. return -1;
  43. if ((busnum == 0) && (devfn >= PCI_DEVFN(31, 0)))
  44. return -1; /* Because of a bug in the galileo (for slot 31). */
  45. /* Clear cause register bits */
  46. GT_WRITE(GT_INTRCAUSE_OFS, ~(GT_INTRCAUSE_MASABORT0_BIT |
  47. GT_INTRCAUSE_TARABORT0_BIT));
  48. /* Setup address */
  49. GT_WRITE(GT_PCI0_CFGADDR_OFS,
  50. (busnum << GT_PCI0_CFGADDR_BUSNUM_SHF) |
  51. (devfn << GT_PCI0_CFGADDR_FUNCTNUM_SHF) |
  52. ((where / 4) << GT_PCI0_CFGADDR_REGNUM_SHF) |
  53. GT_PCI0_CFGADDR_CONFIGEN_BIT);
  54. if (access_type == PCI_ACCESS_WRITE) {
  55. if (busnum == 0 && PCI_SLOT(devfn) == 0) {
  56. /*
  57. * The Galileo system controller is acting
  58. * differently than other devices.
  59. */
  60. GT_WRITE(GT_PCI0_CFGDATA_OFS, *data);
  61. } else
  62. __GT_WRITE(GT_PCI0_CFGDATA_OFS, *data);
  63. } else {
  64. if (busnum == 0 && PCI_SLOT(devfn) == 0) {
  65. /*
  66. * The Galileo system controller is acting
  67. * differently than other devices.
  68. */
  69. *data = GT_READ(GT_PCI0_CFGDATA_OFS);
  70. } else
  71. *data = __GT_READ(GT_PCI0_CFGDATA_OFS);
  72. }
  73. /* Check for master or target abort */
  74. intr = GT_READ(GT_INTRCAUSE_OFS);
  75. if (intr & (GT_INTRCAUSE_MASABORT0_BIT | GT_INTRCAUSE_TARABORT0_BIT)) {
  76. /* Error occurred */
  77. /* Clear bits */
  78. GT_WRITE(GT_INTRCAUSE_OFS, ~(GT_INTRCAUSE_MASABORT0_BIT |
  79. GT_INTRCAUSE_TARABORT0_BIT));
  80. return -1;
  81. }
  82. return 0;
  83. }
  84. /*
  85. * We can't address 8 and 16 bit words directly. Instead we have to
  86. * read/write a 32bit word and mask/modify the data we actually want.
  87. */
  88. static int gt64120_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  89. int where, int size, u32 * val)
  90. {
  91. u32 data = 0;
  92. if (gt64120_pcibios_config_access(PCI_ACCESS_READ, bus, devfn, where,
  93. &data))
  94. return PCIBIOS_DEVICE_NOT_FOUND;
  95. if (size == 1)
  96. *val = (data >> ((where & 3) << 3)) & 0xff;
  97. else if (size == 2)
  98. *val = (data >> ((where & 3) << 3)) & 0xffff;
  99. else
  100. *val = data;
  101. return PCIBIOS_SUCCESSFUL;
  102. }
  103. static int gt64120_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  104. int where, int size, u32 val)
  105. {
  106. u32 data = 0;
  107. if (size == 4)
  108. data = val;
  109. else {
  110. if (gt64120_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
  111. where, &data))
  112. return PCIBIOS_DEVICE_NOT_FOUND;
  113. if (size == 1)
  114. data = (data & ~(0xff << ((where & 3) << 3))) |
  115. (val << ((where & 3) << 3));
  116. else if (size == 2)
  117. data = (data & ~(0xffff << ((where & 3) << 3))) |
  118. (val << ((where & 3) << 3));
  119. }
  120. if (gt64120_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn, where,
  121. &data))
  122. return PCIBIOS_DEVICE_NOT_FOUND;
  123. return PCIBIOS_SUCCESSFUL;
  124. }
  125. struct pci_ops gt64120_pci_ops = {
  126. .read = gt64120_pcibios_read,
  127. .write = gt64120_pcibios_write
  128. };