pci-bcm1480ht.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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/config.h>
  34. #include <linux/types.h>
  35. #include <linux/pci.h>
  36. #include <linux/kernel.h>
  37. #include <linux/init.h>
  38. #include <linux/mm.h>
  39. #include <linux/console.h>
  40. #include <linux/tty.h>
  41. #include <asm/sibyte/bcm1480_regs.h>
  42. #include <asm/sibyte/bcm1480_scd.h>
  43. #include <asm/sibyte/board.h>
  44. #include <asm/io.h>
  45. /*
  46. * Macros for calculating offsets into config space given a device
  47. * structure or dev/fun/reg
  48. */
  49. #define CFGOFFSET(bus,devfn,where) (((bus)<<16)+((devfn)<<8)+(where))
  50. #define CFGADDR(bus,devfn,where) CFGOFFSET((bus)->number,(devfn),where)
  51. static void *ht_cfg_space;
  52. #define PCI_BUS_ENABLED 1
  53. #define PCI_DEVICE_MODE 2
  54. static int bcm1480ht_bus_status = 0;
  55. #define PCI_BRIDGE_DEVICE 0
  56. #define HT_BRIDGE_DEVICE 1
  57. /*
  58. * HT's level-sensitive interrupts require EOI, which is generated
  59. * through a 4MB memory-mapped region
  60. */
  61. unsigned long ht_eoi_space;
  62. /*
  63. * Read/write 32-bit values in config space.
  64. */
  65. static inline u32 READCFG32(u32 addr)
  66. {
  67. return *(u32 *)(ht_cfg_space + (addr&~3));
  68. }
  69. static inline void WRITECFG32(u32 addr, u32 data)
  70. {
  71. *(u32 *)(ht_cfg_space + (addr & ~3)) = data;
  72. }
  73. /*
  74. * Some checks before doing config cycles:
  75. * In PCI Device Mode, hide everything on bus 0 except the LDT host
  76. * bridge. Otherwise, access is controlled by bridge MasterEn bits.
  77. */
  78. static int bcm1480ht_can_access(struct pci_bus *bus, int devfn)
  79. {
  80. u32 devno;
  81. if (!(bcm1480ht_bus_status & (PCI_BUS_ENABLED | PCI_DEVICE_MODE)))
  82. return 0;
  83. if (bus->number == 0) {
  84. devno = PCI_SLOT(devfn);
  85. if (bcm1480ht_bus_status & PCI_DEVICE_MODE)
  86. return 0;
  87. }
  88. return 1;
  89. }
  90. /*
  91. * Read/write access functions for various sizes of values
  92. * in config space. Return all 1's for disallowed accesses
  93. * for a kludgy but adequate simulation of master aborts.
  94. */
  95. static int bcm1480ht_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  96. int where, int size, u32 * val)
  97. {
  98. u32 data = 0;
  99. if ((size == 2) && (where & 1))
  100. return PCIBIOS_BAD_REGISTER_NUMBER;
  101. else if ((size == 4) && (where & 3))
  102. return PCIBIOS_BAD_REGISTER_NUMBER;
  103. if (bcm1480ht_can_access(bus, devfn))
  104. data = READCFG32(CFGADDR(bus, devfn, where));
  105. else
  106. data = 0xFFFFFFFF;
  107. if (size == 1)
  108. *val = (data >> ((where & 3) << 3)) & 0xff;
  109. else if (size == 2)
  110. *val = (data >> ((where & 3) << 3)) & 0xffff;
  111. else
  112. *val = data;
  113. return PCIBIOS_SUCCESSFUL;
  114. }
  115. static int bcm1480ht_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  116. int where, int size, u32 val)
  117. {
  118. u32 cfgaddr = CFGADDR(bus, devfn, where);
  119. u32 data = 0;
  120. if ((size == 2) && (where & 1))
  121. return PCIBIOS_BAD_REGISTER_NUMBER;
  122. else if ((size == 4) && (where & 3))
  123. return PCIBIOS_BAD_REGISTER_NUMBER;
  124. if (!bcm1480ht_can_access(bus, devfn))
  125. return PCIBIOS_BAD_REGISTER_NUMBER;
  126. data = READCFG32(cfgaddr);
  127. if (size == 1)
  128. data = (data & ~(0xff << ((where & 3) << 3))) |
  129. (val << ((where & 3) << 3));
  130. else if (size == 2)
  131. data = (data & ~(0xffff << ((where & 3) << 3))) |
  132. (val << ((where & 3) << 3));
  133. else
  134. data = val;
  135. WRITECFG32(cfgaddr, data);
  136. return PCIBIOS_SUCCESSFUL;
  137. }
  138. static int bcm1480ht_pcibios_get_busno(void)
  139. {
  140. return 0;
  141. }
  142. struct pci_ops bcm1480ht_pci_ops = {
  143. .read = bcm1480ht_pcibios_read,
  144. .write = bcm1480ht_pcibios_write,
  145. };
  146. static struct resource bcm1480ht_mem_resource = {
  147. .name = "BCM1480 HT MEM",
  148. .start = 0x40000000UL,
  149. .end = 0x5fffffffUL,
  150. .flags = IORESOURCE_MEM,
  151. };
  152. static struct resource bcm1480ht_io_resource = {
  153. .name = "BCM1480 HT I/O",
  154. .start = 0x00000000UL,
  155. .end = 0x01ffffffUL,
  156. .flags = IORESOURCE_IO,
  157. };
  158. struct pci_controller bcm1480ht_controller = {
  159. .pci_ops = &bcm1480ht_pci_ops,
  160. .mem_resource = &bcm1480ht_mem_resource,
  161. .io_resource = &bcm1480ht_io_resource,
  162. .index = 1,
  163. .get_busno = bcm1480ht_pcibios_get_busno,
  164. };
  165. static int __init bcm1480ht_pcibios_init(void)
  166. {
  167. uint32_t cmdreg;
  168. ht_cfg_space = ioremap(A_BCM1480_PHYS_HT_CFG_MATCH_BITS, 16*1024*1024);
  169. /*
  170. * See if the PCI bus has been configured by the firmware.
  171. */
  172. cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0),
  173. PCI_COMMAND));
  174. if (!(cmdreg & PCI_COMMAND_MASTER)) {
  175. printk("HT: Skipping HT probe. Bus is not initialized.\n");
  176. iounmap(ht_cfg_space);
  177. return 1; /* XXX */
  178. }
  179. bcm1480ht_bus_status |= PCI_BUS_ENABLED;
  180. ht_eoi_space = (unsigned long)
  181. ioremap(A_BCM1480_PHYS_HT_SPECIAL_MATCH_BYTES,
  182. 4 * 1024 * 1024);
  183. register_pci_controller(&bcm1480ht_controller);
  184. return 0;
  185. }
  186. arch_initcall(bcm1480ht_pcibios_init);