ops-it8172.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. * IT8172 system controller specific pci support.
  5. *
  6. * Copyright 2000 MontaVista Software Inc.
  7. * Author: MontaVista Software, Inc.
  8. * ppopov@mvista.com or source@mvista.com
  9. *
  10. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  20. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  23. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * You should have received a copy of the GNU General Public License along
  29. * with this program; if not, write to the Free Software Foundation, Inc.,
  30. * 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #include <linux/types.h>
  33. #include <linux/pci.h>
  34. #include <linux/kernel.h>
  35. #include <linux/init.h>
  36. #include <asm/it8172/it8172.h>
  37. #include <asm/it8172/it8172_pci.h>
  38. #define PCI_ACCESS_READ 0
  39. #define PCI_ACCESS_WRITE 1
  40. #undef DEBUG
  41. #ifdef DEBUG
  42. #define DBG(x...) printk(x)
  43. #else
  44. #define DBG(x...)
  45. #endif
  46. static struct resource pci_mem_resource_1;
  47. static struct resource pci_io_resource = {
  48. "io pci IO space",
  49. 0x14018000,
  50. 0x17FFFFFF,
  51. IORESOURCE_IO
  52. };
  53. static struct resource pci_mem_resource_0 = {
  54. "ext pci memory space 0/1",
  55. 0x10101000,
  56. 0x13FFFFFF,
  57. IORESOURCE_MEM,
  58. &pci_mem_resource_0,
  59. NULL,
  60. &pci_mem_resource_1
  61. };
  62. static struct resource pci_mem_resource_1 = {
  63. "ext pci memory space 2/3",
  64. 0x1A000000,
  65. 0x1FBFFFFF,
  66. IORESOURCE_MEM,
  67. &pci_mem_resource_0,
  68. NULL,
  69. NULL
  70. };
  71. extern struct pci_ops it8172_pci_ops;
  72. struct pci_controller it8172_controller = {
  73. .pci_ops = &it8172_pci_ops,
  74. .io_resource = &pci_io_resource,
  75. .mem_resource = &pci_mem_resource_0,
  76. };
  77. static int it8172_pcibios_config_access(unsigned char access_type,
  78. struct pci_bus *bus,
  79. unsigned int devfn, int where,
  80. u32 * data)
  81. {
  82. /*
  83. * config cycles are on 4 byte boundary only
  84. */
  85. /* Setup address */
  86. IT_WRITE(IT_CONFADDR, (bus->number << IT_BUSNUM_SHF) |
  87. (devfn << IT_FUNCNUM_SHF) | (where & ~0x3));
  88. if (access_type == PCI_ACCESS_WRITE) {
  89. IT_WRITE(IT_CONFDATA, *data);
  90. } else {
  91. IT_READ(IT_CONFDATA, *data);
  92. }
  93. /*
  94. * Revisit: check for master or target abort.
  95. */
  96. return 0;
  97. }
  98. /*
  99. * We can't address 8 and 16 bit words directly. Instead we have to
  100. * read/write a 32bit word and mask/modify the data we actually want.
  101. */
  102. static write_config(struct pci_bus *bus, unsigned int devfn, int where,
  103. int size, u32 val)
  104. {
  105. u32 data = 0;
  106. switch (size) {
  107. case 1:
  108. if (it8172_pcibios_config_access
  109. (PCI_ACCESS_READ, dev, where, &data))
  110. return -1;
  111. *val = (data >> ((where & 3) << 3)) & 0xff;
  112. return PCIBIOS_SUCCESSFUL;
  113. case 2:
  114. if (where & 1)
  115. return PCIBIOS_BAD_REGISTER_NUMBER;
  116. if (it8172_pcibios_config_access
  117. (PCI_ACCESS_READ, dev, where, &data))
  118. return -1;
  119. *val = (data >> ((where & 3) << 3)) & 0xffff;
  120. DBG("cfg read word: bus %d dev_fn %x where %x: val %x\n",
  121. dev->bus->number, dev->devfn, where, *val);
  122. return PCIBIOS_SUCCESSFUL;
  123. case 4:
  124. if (where & 3)
  125. return PCIBIOS_BAD_REGISTER_NUMBER;
  126. if (it8172_pcibios_config_access
  127. (PCI_ACCESS_READ, dev, where, &data))
  128. return -1;
  129. *val = data;
  130. return PCIBIOS_SUCCESSFUL;
  131. }
  132. }
  133. static write_config(struct pci_bus *bus, unsigned int devfn, int where,
  134. int size, u32 val)
  135. {
  136. u32 data = 0;
  137. switch (size) {
  138. case 1:
  139. if (it8172_pcibios_config_access
  140. (PCI_ACCESS_READ, dev, where, &data))
  141. return -1;
  142. data = (data & ~(0xff << ((where & 3) << 3))) |
  143. (val << ((where & 3) << 3));
  144. if (it8172_pcibios_config_access
  145. (PCI_ACCESS_WRITE, dev, where, &data))
  146. return -1;
  147. return PCIBIOS_SUCCESSFUL;
  148. case 2:
  149. if (where & 1)
  150. return PCIBIOS_BAD_REGISTER_NUMBER;
  151. if (it8172_pcibios_config_access
  152. (PCI_ACCESS_READ, dev, where, &data))
  153. eturn - 1;
  154. data = (data & ~(0xffff << ((where & 3) << 3))) |
  155. (val << ((where & 3) << 3));
  156. if (it8172_pcibios_config_access
  157. (PCI_ACCESS_WRITE, dev, where, &data))
  158. return -1;
  159. return PCIBIOS_SUCCESSFUL;
  160. case 4:
  161. if (where & 3)
  162. return PCIBIOS_BAD_REGISTER_NUMBER;
  163. if (it8172_pcibios_config_access
  164. (PCI_ACCESS_WRITE, dev, where, &val))
  165. return -1;
  166. return PCIBIOS_SUCCESSFUL;
  167. }
  168. }
  169. struct pci_ops it8172_pci_ops = {
  170. .read = read_config,
  171. .write = write_config,
  172. };