ops-gt64xxx_pci0.c 4.1 KB

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