pci-bcm1480.c 6.8 KB

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