pci-bcm1480ht.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright (C) 2001,2002,2005 Broadcom Corporation
  3. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. * BCM1480/1455-specific HT support (looking like PCI)
  21. *
  22. * This module provides the glue between Linux's PCI subsystem
  23. * and the hardware. We basically provide glue for accessing
  24. * configuration space, and set up the translation for I/O
  25. * space accesses.
  26. *
  27. * To access configuration space, we use ioremap. In the 32-bit
  28. * kernel, this consumes either 4 or 8 page table pages, and 16MB of
  29. * kernel mapped memory. Hopefully neither of these should be a huge
  30. * problem.
  31. *
  32. */
  33. #include <linux/types.h>
  34. #include <linux/pci.h>
  35. #include <linux/kernel.h>
  36. #include <linux/init.h>
  37. #include <linux/mm.h>
  38. #include <linux/console.h>
  39. #include <linux/tty.h>
  40. #include <asm/sibyte/bcm1480_regs.h>
  41. #include <asm/sibyte/bcm1480_scd.h>
  42. #include <asm/sibyte/board.h>
  43. #include <asm/io.h>
  44. /*
  45. * Macros for calculating offsets into config space given a device
  46. * structure or dev/fun/reg
  47. */
  48. #define CFGOFFSET(bus, devfn, where) (((bus)<<16)+((devfn)<<8)+(where))
  49. #define CFGADDR(bus, devfn, where) CFGOFFSET((bus)->number, (devfn), where)
  50. static void *ht_cfg_space;
  51. #define PCI_BUS_ENABLED 1
  52. #define PCI_DEVICE_MODE 2
  53. static int bcm1480ht_bus_status;
  54. #define PCI_BRIDGE_DEVICE 0
  55. #define HT_BRIDGE_DEVICE 1
  56. /*
  57. * HT's level-sensitive interrupts require EOI, which is generated
  58. * through a 4MB memory-mapped region
  59. */
  60. unsigned long ht_eoi_space;
  61. /*
  62. * Read/write 32-bit values in config space.
  63. */
  64. static inline u32 READCFG32(u32 addr)
  65. {
  66. return *(u32 *)(ht_cfg_space + (addr&~3));
  67. }
  68. static inline void WRITECFG32(u32 addr, u32 data)
  69. {
  70. *(u32 *)(ht_cfg_space + (addr & ~3)) = data;
  71. }
  72. /*
  73. * Some checks before doing config cycles:
  74. * In PCI Device Mode, hide everything on bus 0 except the LDT host
  75. * bridge. Otherwise, access is controlled by bridge MasterEn bits.
  76. */
  77. static int bcm1480ht_can_access(struct pci_bus *bus, int devfn)
  78. {
  79. u32 devno;
  80. if (!(bcm1480ht_bus_status & (PCI_BUS_ENABLED | PCI_DEVICE_MODE)))
  81. return 0;
  82. if (bus->number == 0) {
  83. devno = PCI_SLOT(devfn);
  84. if (bcm1480ht_bus_status & PCI_DEVICE_MODE)
  85. return 0;
  86. }
  87. return 1;
  88. }
  89. /*
  90. * Read/write access functions for various sizes of values
  91. * in config space. Return all 1's for disallowed accesses
  92. * for a kludgy but adequate simulation of master aborts.
  93. */
  94. static int bcm1480ht_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  95. int where, int size, u32 * val)
  96. {
  97. u32 data = 0;
  98. if ((size == 2) && (where & 1))
  99. return PCIBIOS_BAD_REGISTER_NUMBER;
  100. else if ((size == 4) && (where & 3))
  101. return PCIBIOS_BAD_REGISTER_NUMBER;
  102. if (bcm1480ht_can_access(bus, devfn))
  103. data = READCFG32(CFGADDR(bus, devfn, where));
  104. else
  105. data = 0xFFFFFFFF;
  106. if (size == 1)
  107. *val = (data >> ((where & 3) << 3)) & 0xff;
  108. else if (size == 2)
  109. *val = (data >> ((where & 3) << 3)) & 0xffff;
  110. else
  111. *val = data;
  112. return PCIBIOS_SUCCESSFUL;
  113. }
  114. static int bcm1480ht_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  115. int where, int size, u32 val)
  116. {
  117. u32 cfgaddr = CFGADDR(bus, devfn, where);
  118. u32 data = 0;
  119. if ((size == 2) && (where & 1))
  120. return PCIBIOS_BAD_REGISTER_NUMBER;
  121. else if ((size == 4) && (where & 3))
  122. return PCIBIOS_BAD_REGISTER_NUMBER;
  123. if (!bcm1480ht_can_access(bus, devfn))
  124. return PCIBIOS_BAD_REGISTER_NUMBER;
  125. data = READCFG32(cfgaddr);
  126. if (size == 1)
  127. data = (data & ~(0xff << ((where & 3) << 3))) |
  128. (val << ((where & 3) << 3));
  129. else if (size == 2)
  130. data = (data & ~(0xffff << ((where & 3) << 3))) |
  131. (val << ((where & 3) << 3));
  132. else
  133. data = val;
  134. WRITECFG32(cfgaddr, data);
  135. return PCIBIOS_SUCCESSFUL;
  136. }
  137. static int bcm1480ht_pcibios_get_busno(void)
  138. {
  139. return 0;
  140. }
  141. struct pci_ops bcm1480ht_pci_ops = {
  142. .read = bcm1480ht_pcibios_read,
  143. .write = bcm1480ht_pcibios_write,
  144. };
  145. static struct resource bcm1480ht_mem_resource = {
  146. .name = "BCM1480 HT MEM",
  147. .start = A_BCM1480_PHYS_HT_MEM_MATCH_BYTES,
  148. .end = A_BCM1480_PHYS_HT_MEM_MATCH_BYTES + 0x1fffffffUL,
  149. .flags = IORESOURCE_MEM,
  150. };
  151. static struct resource bcm1480ht_io_resource = {
  152. .name = "BCM1480 HT I/O",
  153. .start = A_BCM1480_PHYS_HT_IO_MATCH_BYTES,
  154. .end = A_BCM1480_PHYS_HT_IO_MATCH_BYTES + 0x01ffffffUL,
  155. .flags = IORESOURCE_IO,
  156. };
  157. struct pci_controller bcm1480ht_controller = {
  158. .pci_ops = &bcm1480ht_pci_ops,
  159. .mem_resource = &bcm1480ht_mem_resource,
  160. .io_resource = &bcm1480ht_io_resource,
  161. .index = 1,
  162. .get_busno = bcm1480ht_pcibios_get_busno,
  163. .io_offset = A_BCM1480_PHYS_HT_IO_MATCH_BYTES,
  164. };
  165. static int __init bcm1480ht_pcibios_init(void)
  166. {
  167. ht_cfg_space = ioremap(A_BCM1480_PHYS_HT_CFG_MATCH_BITS, 16*1024*1024);
  168. /* CFE doesn't always init all HT paths, so we always scan */
  169. bcm1480ht_bus_status |= PCI_BUS_ENABLED;
  170. ht_eoi_space = (unsigned long)
  171. ioremap(A_BCM1480_PHYS_HT_SPECIAL_MATCH_BYTES,
  172. 4 * 1024 * 1024);
  173. bcm1480ht_controller.io_map_base = (unsigned long)
  174. ioremap(A_BCM1480_PHYS_HT_IO_MATCH_BYTES, 65536);
  175. bcm1480ht_controller.io_map_base -= bcm1480ht_controller.io_offset;
  176. register_pci_controller(&bcm1480ht_controller);
  177. return 0;
  178. }
  179. arch_initcall(bcm1480ht_pcibios_init);