pci-bcm1480.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. * BCM1x80/1x55-specific PCI support
  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. * XXX: AT THIS TIME, ONLY the NATIVE PCI-X INTERFACE IS SUPPORTED.
  33. */
  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 <linux/vt.h>
  42. #include <asm/sibyte/bcm1480_regs.h>
  43. #include <asm/sibyte/bcm1480_scd.h>
  44. #include <asm/sibyte/board.h>
  45. #include <asm/io.h>
  46. /*
  47. * Macros for calculating offsets into config space given a device
  48. * structure or dev/fun/reg
  49. */
  50. #define CFGOFFSET(bus, devfn, where) (((bus)<<16)+((devfn)<<8)+(where))
  51. #define CFGADDR(bus, devfn, where) CFGOFFSET((bus)->number, (devfn), where)
  52. static void *cfg_space;
  53. #define PCI_BUS_ENABLED 1
  54. #define PCI_DEVICE_MODE 2
  55. static int bcm1480_bus_status;
  56. #define PCI_BRIDGE_DEVICE 0
  57. /*
  58. * Read/write 32-bit values in config space.
  59. */
  60. static inline u32 READCFG32(u32 addr)
  61. {
  62. return *(u32 *)(cfg_space + (addr&~3));
  63. }
  64. static inline void WRITECFG32(u32 addr, u32 data)
  65. {
  66. *(u32 *)(cfg_space + (addr & ~3)) = data;
  67. }
  68. int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  69. {
  70. if (pin == 0)
  71. return -1;
  72. return K_BCM1480_INT_PCI_INTA - 1 + pin;
  73. }
  74. /* Do platform specific device initialization at pci_enable_device() time */
  75. int pcibios_plat_dev_init(struct pci_dev *dev)
  76. {
  77. return 0;
  78. }
  79. /*
  80. * Some checks before doing config cycles:
  81. * In PCI Device Mode, hide everything on bus 0 except the LDT host
  82. * bridge. Otherwise, access is controlled by bridge MasterEn bits.
  83. */
  84. static int bcm1480_pci_can_access(struct pci_bus *bus, int devfn)
  85. {
  86. u32 devno;
  87. if (!(bcm1480_bus_status & (PCI_BUS_ENABLED | PCI_DEVICE_MODE)))
  88. return 0;
  89. if (bus->number == 0) {
  90. devno = PCI_SLOT(devfn);
  91. if (bcm1480_bus_status & PCI_DEVICE_MODE)
  92. return 0;
  93. else
  94. return 1;
  95. } else
  96. return 1;
  97. }
  98. /*
  99. * Read/write access functions for various sizes of values
  100. * in config space. Return all 1's for disallowed accesses
  101. * for a kludgy but adequate simulation of master aborts.
  102. */
  103. static int bcm1480_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  104. int where, int size, u32 * val)
  105. {
  106. u32 data = 0;
  107. if ((size == 2) && (where & 1))
  108. return PCIBIOS_BAD_REGISTER_NUMBER;
  109. else if ((size == 4) && (where & 3))
  110. return PCIBIOS_BAD_REGISTER_NUMBER;
  111. if (bcm1480_pci_can_access(bus, devfn))
  112. data = READCFG32(CFGADDR(bus, devfn, where));
  113. else
  114. data = 0xFFFFFFFF;
  115. if (size == 1)
  116. *val = (data >> ((where & 3) << 3)) & 0xff;
  117. else if (size == 2)
  118. *val = (data >> ((where & 3) << 3)) & 0xffff;
  119. else
  120. *val = data;
  121. return PCIBIOS_SUCCESSFUL;
  122. }
  123. static int bcm1480_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  124. int where, int size, u32 val)
  125. {
  126. u32 cfgaddr = CFGADDR(bus, devfn, where);
  127. u32 data = 0;
  128. if ((size == 2) && (where & 1))
  129. return PCIBIOS_BAD_REGISTER_NUMBER;
  130. else if ((size == 4) && (where & 3))
  131. return PCIBIOS_BAD_REGISTER_NUMBER;
  132. if (!bcm1480_pci_can_access(bus, devfn))
  133. return PCIBIOS_BAD_REGISTER_NUMBER;
  134. data = READCFG32(cfgaddr);
  135. if (size == 1)
  136. data = (data & ~(0xff << ((where & 3) << 3))) |
  137. (val << ((where & 3) << 3));
  138. else if (size == 2)
  139. data = (data & ~(0xffff << ((where & 3) << 3))) |
  140. (val << ((where & 3) << 3));
  141. else
  142. data = val;
  143. WRITECFG32(cfgaddr, data);
  144. return PCIBIOS_SUCCESSFUL;
  145. }
  146. struct pci_ops bcm1480_pci_ops = {
  147. .read = bcm1480_pcibios_read,
  148. .write = bcm1480_pcibios_write,
  149. };
  150. static struct resource bcm1480_mem_resource = {
  151. .name = "BCM1480 PCI MEM",
  152. .start = A_BCM1480_PHYS_PCI_MEM_MATCH_BYTES,
  153. .end = A_BCM1480_PHYS_PCI_MEM_MATCH_BYTES + 0xfffffffUL,
  154. .flags = IORESOURCE_MEM,
  155. };
  156. static struct resource bcm1480_io_resource = {
  157. .name = "BCM1480 PCI I/O",
  158. .start = A_BCM1480_PHYS_PCI_IO_MATCH_BYTES,
  159. .end = A_BCM1480_PHYS_PCI_IO_MATCH_BYTES + 0x1ffffffUL,
  160. .flags = IORESOURCE_IO,
  161. };
  162. struct pci_controller bcm1480_controller = {
  163. .pci_ops = &bcm1480_pci_ops,
  164. .mem_resource = &bcm1480_mem_resource,
  165. .io_resource = &bcm1480_io_resource,
  166. .io_offset = A_BCM1480_PHYS_PCI_IO_MATCH_BYTES,
  167. };
  168. static int __init bcm1480_pcibios_init(void)
  169. {
  170. uint32_t cmdreg;
  171. uint64_t reg;
  172. /* CFE will assign PCI resources */
  173. pci_set_flags(PCI_PROBE_ONLY);
  174. /* Avoid ISA compat ranges. */
  175. PCIBIOS_MIN_IO = 0x00008000UL;
  176. PCIBIOS_MIN_MEM = 0x01000000UL;
  177. /* Set I/O resource limits. - unlimited for now to accommodate HT */
  178. ioport_resource.end = 0xffffffffUL;
  179. iomem_resource.end = 0xffffffffUL;
  180. cfg_space = ioremap(A_BCM1480_PHYS_PCI_CFG_MATCH_BITS, 16*1024*1024);
  181. /*
  182. * See if the PCI bus has been configured by the firmware.
  183. */
  184. reg = __raw_readq(IOADDR(A_SCD_SYSTEM_CFG));
  185. if (!(reg & M_BCM1480_SYS_PCI_HOST)) {
  186. bcm1480_bus_status |= PCI_DEVICE_MODE;
  187. } else {
  188. cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0),
  189. PCI_COMMAND));
  190. if (!(cmdreg & PCI_COMMAND_MASTER)) {
  191. printk
  192. ("PCI: Skipping PCI probe. Bus is not initialized.\n");
  193. iounmap(cfg_space);
  194. return 1; /* XXX */
  195. }
  196. bcm1480_bus_status |= PCI_BUS_ENABLED;
  197. }
  198. /* turn on ExpMemEn */
  199. cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0), 0x40));
  200. WRITECFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0), 0x40),
  201. cmdreg | 0x10);
  202. cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0), 0x40));
  203. /*
  204. * Establish mappings in KSEG2 (kernel virtual) to PCI I/O
  205. * space. Use "match bytes" policy to make everything look
  206. * little-endian. So, you need to also set
  207. * CONFIG_SWAP_IO_SPACE, but this is the combination that
  208. * works correctly with most of Linux's drivers.
  209. * XXX ehs: Should this happen in PCI Device mode?
  210. */
  211. bcm1480_controller.io_map_base = (unsigned long)
  212. ioremap(A_BCM1480_PHYS_PCI_IO_MATCH_BYTES, 65536);
  213. bcm1480_controller.io_map_base -= bcm1480_controller.io_offset;
  214. set_io_port_base(bcm1480_controller.io_map_base);
  215. register_pci_controller(&bcm1480_controller);
  216. #ifdef CONFIG_VGA_CONSOLE
  217. console_lock();
  218. do_take_over_console(&vga_con, 0, MAX_NR_CONSOLES-1, 1);
  219. console_unlock();
  220. #endif
  221. return 0;
  222. }
  223. arch_initcall(bcm1480_pcibios_init);