pci-bcm1480.c 6.9 KB

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