ops-it8172.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. .start = 0x14018000,
  49. .end = 0x17FFFFFF,
  50. .name = "io pci IO space",
  51. .flags = IORESOURCE_IO
  52. };
  53. static struct resource pci_mem_resource_0 = {
  54. .start = 0x10101000,
  55. .end = 0x13FFFFFF,
  56. .name = "ext pci memory space 0/1",
  57. .flags = IORESOURCE_MEM,
  58. .parent = &pci_mem_resource_0,
  59. .sibling = NULL,
  60. .child = &pci_mem_resource_1
  61. };
  62. static struct resource pci_mem_resource_1 = {
  63. .start = 0x1A000000,
  64. .end = 0x1FBFFFFF,
  65. .name = "ext pci memory space 2/3",
  66. .flags = IORESOURCE_MEM,
  67. .parent = &pci_mem_resource_0
  68. };
  69. extern struct pci_ops it8172_pci_ops;
  70. struct pci_controller it8172_controller = {
  71. .pci_ops = &it8172_pci_ops,
  72. .io_resource = &pci_io_resource,
  73. .mem_resource = &pci_mem_resource_0,
  74. };
  75. static int it8172_pcibios_config_access(unsigned char access_type,
  76. struct pci_bus *bus,
  77. unsigned int devfn, int where,
  78. u32 * data)
  79. {
  80. /*
  81. * config cycles are on 4 byte boundary only
  82. */
  83. /* Setup address */
  84. IT_WRITE(IT_CONFADDR, (bus->number << IT_BUSNUM_SHF) |
  85. (devfn << IT_FUNCNUM_SHF) | (where & ~0x3));
  86. if (access_type == PCI_ACCESS_WRITE) {
  87. IT_WRITE(IT_CONFDATA, *data);
  88. } else {
  89. IT_READ(IT_CONFDATA, *data);
  90. }
  91. /*
  92. * Revisit: check for master or target abort.
  93. */
  94. return 0;
  95. }
  96. /*
  97. * We can't address 8 and 16 bit words directly. Instead we have to
  98. * read/write a 32bit word and mask/modify the data we actually want.
  99. */
  100. static write_config(struct pci_bus *bus, unsigned int devfn, int where,
  101. int size, u32 val)
  102. {
  103. u32 data = 0;
  104. switch (size) {
  105. case 1:
  106. if (it8172_pcibios_config_access
  107. (PCI_ACCESS_READ, dev, where, &data))
  108. return -1;
  109. *val = (data >> ((where & 3) << 3)) & 0xff;
  110. return PCIBIOS_SUCCESSFUL;
  111. case 2:
  112. if (where & 1)
  113. return PCIBIOS_BAD_REGISTER_NUMBER;
  114. if (it8172_pcibios_config_access
  115. (PCI_ACCESS_READ, dev, where, &data))
  116. return -1;
  117. *val = (data >> ((where & 3) << 3)) & 0xffff;
  118. DBG("cfg read word: bus %d dev_fn %x where %x: val %x\n",
  119. dev->bus->number, dev->devfn, where, *val);
  120. return PCIBIOS_SUCCESSFUL;
  121. case 4:
  122. if (where & 3)
  123. return PCIBIOS_BAD_REGISTER_NUMBER;
  124. if (it8172_pcibios_config_access
  125. (PCI_ACCESS_READ, dev, where, &data))
  126. return -1;
  127. *val = data;
  128. return PCIBIOS_SUCCESSFUL;
  129. }
  130. }
  131. static write_config(struct pci_bus *bus, unsigned int devfn, int where,
  132. int size, u32 val)
  133. {
  134. u32 data = 0;
  135. switch (size) {
  136. case 1:
  137. if (it8172_pcibios_config_access
  138. (PCI_ACCESS_READ, dev, where, &data))
  139. return -1;
  140. data = (data & ~(0xff << ((where & 3) << 3))) |
  141. (val << ((where & 3) << 3));
  142. if (it8172_pcibios_config_access
  143. (PCI_ACCESS_WRITE, dev, where, &data))
  144. return -1;
  145. return PCIBIOS_SUCCESSFUL;
  146. case 2:
  147. if (where & 1)
  148. return PCIBIOS_BAD_REGISTER_NUMBER;
  149. if (it8172_pcibios_config_access
  150. (PCI_ACCESS_READ, dev, where, &data))
  151. eturn - 1;
  152. data = (data & ~(0xffff << ((where & 3) << 3))) |
  153. (val << ((where & 3) << 3));
  154. if (it8172_pcibios_config_access
  155. (PCI_ACCESS_WRITE, dev, where, &data))
  156. return -1;
  157. return PCIBIOS_SUCCESSFUL;
  158. case 4:
  159. if (where & 3)
  160. return PCIBIOS_BAD_REGISTER_NUMBER;
  161. if (it8172_pcibios_config_access
  162. (PCI_ACCESS_WRITE, dev, where, &val))
  163. return -1;
  164. return PCIBIOS_SUCCESSFUL;
  165. }
  166. }
  167. struct pci_ops it8172_pci_ops = {
  168. .read = read_config,
  169. .write = write_config,
  170. };