pci-sb1250.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 2001,2002,2003 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. * BCM1250-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. #include <linux/types.h>
  33. #include <linux/pci.h>
  34. #include <linux/kernel.h>
  35. #include <linux/init.h>
  36. #include <linux/mm.h>
  37. #include <linux/console.h>
  38. #include <linux/tty.h>
  39. #include <asm/io.h>
  40. #include <asm/sibyte/sb1250_defs.h>
  41. #include <asm/sibyte/sb1250_regs.h>
  42. #include <asm/sibyte/sb1250_scd.h>
  43. #include <asm/sibyte/board.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 *cfg_space;
  51. #define PCI_BUS_ENABLED 1
  52. #define LDT_BUS_ENABLED 2
  53. #define PCI_DEVICE_MODE 4
  54. static int sb1250_bus_status = 0;
  55. #define PCI_BRIDGE_DEVICE 0
  56. #define LDT_BRIDGE_DEVICE 1
  57. #ifdef CONFIG_SIBYTE_HAS_LDT
  58. /*
  59. * HT's level-sensitive interrupts require EOI, which is generated
  60. * through a 4MB memory-mapped region
  61. */
  62. unsigned long ldt_eoi_space;
  63. #endif
  64. /*
  65. * Read/write 32-bit values in config space.
  66. */
  67. static inline u32 READCFG32(u32 addr)
  68. {
  69. return *(u32 *) (cfg_space + (addr & ~3));
  70. }
  71. static inline void WRITECFG32(u32 addr, u32 data)
  72. {
  73. *(u32 *) (cfg_space + (addr & ~3)) = data;
  74. }
  75. int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  76. {
  77. return dev->irq;
  78. }
  79. /* Do platform specific device initialization at pci_enable_device() time */
  80. int pcibios_plat_dev_init(struct pci_dev *dev)
  81. {
  82. return 0;
  83. }
  84. /*
  85. * Some checks before doing config cycles:
  86. * In PCI Device Mode, hide everything on bus 0 except the LDT host
  87. * bridge. Otherwise, access is controlled by bridge MasterEn bits.
  88. */
  89. static int sb1250_pci_can_access(struct pci_bus *bus, int devfn)
  90. {
  91. u32 devno;
  92. if (!(sb1250_bus_status & (PCI_BUS_ENABLED | PCI_DEVICE_MODE)))
  93. return 0;
  94. if (bus->number == 0) {
  95. devno = PCI_SLOT(devfn);
  96. if (devno == LDT_BRIDGE_DEVICE)
  97. return (sb1250_bus_status & LDT_BUS_ENABLED) != 0;
  98. else if (sb1250_bus_status & PCI_DEVICE_MODE)
  99. return 0;
  100. else
  101. return 1;
  102. } else
  103. return 1;
  104. }
  105. /*
  106. * Read/write access functions for various sizes of values
  107. * in config space. Return all 1's for disallowed accesses
  108. * for a kludgy but adequate simulation of master aborts.
  109. */
  110. static int sb1250_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  111. int where, int size, u32 * val)
  112. {
  113. u32 data = 0;
  114. if ((size == 2) && (where & 1))
  115. return PCIBIOS_BAD_REGISTER_NUMBER;
  116. else if ((size == 4) && (where & 3))
  117. return PCIBIOS_BAD_REGISTER_NUMBER;
  118. if (sb1250_pci_can_access(bus, devfn))
  119. data = READCFG32(CFGADDR(bus, devfn, where));
  120. else
  121. data = 0xFFFFFFFF;
  122. if (size == 1)
  123. *val = (data >> ((where & 3) << 3)) & 0xff;
  124. else if (size == 2)
  125. *val = (data >> ((where & 3) << 3)) & 0xffff;
  126. else
  127. *val = data;
  128. return PCIBIOS_SUCCESSFUL;
  129. }
  130. static int sb1250_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  131. int where, int size, u32 val)
  132. {
  133. u32 cfgaddr = CFGADDR(bus, devfn, where);
  134. u32 data = 0;
  135. if ((size == 2) && (where & 1))
  136. return PCIBIOS_BAD_REGISTER_NUMBER;
  137. else if ((size == 4) && (where & 3))
  138. return PCIBIOS_BAD_REGISTER_NUMBER;
  139. if (!sb1250_pci_can_access(bus, devfn))
  140. return PCIBIOS_BAD_REGISTER_NUMBER;
  141. data = READCFG32(cfgaddr);
  142. if (size == 1)
  143. data = (data & ~(0xff << ((where & 3) << 3))) |
  144. (val << ((where & 3) << 3));
  145. else if (size == 2)
  146. data = (data & ~(0xffff << ((where & 3) << 3))) |
  147. (val << ((where & 3) << 3));
  148. else
  149. data = val;
  150. WRITECFG32(cfgaddr, data);
  151. return PCIBIOS_SUCCESSFUL;
  152. }
  153. struct pci_ops sb1250_pci_ops = {
  154. .read = sb1250_pcibios_read,
  155. .write = sb1250_pcibios_write,
  156. };
  157. static struct resource sb1250_mem_resource = {
  158. .name = "SB1250 PCI MEM",
  159. .start = 0x40000000UL,
  160. .end = 0x5fffffffUL,
  161. .flags = IORESOURCE_MEM,
  162. };
  163. static struct resource sb1250_io_resource = {
  164. .name = "SB1250 PCI I/O",
  165. .start = 0x00000000UL,
  166. .end = 0x01ffffffUL,
  167. .flags = IORESOURCE_IO,
  168. };
  169. struct pci_controller sb1250_controller = {
  170. .pci_ops = &sb1250_pci_ops,
  171. .mem_resource = &sb1250_mem_resource,
  172. .io_resource = &sb1250_io_resource,
  173. };
  174. static int __init sb1250_pcibios_init(void)
  175. {
  176. void __iomem *io_map_base;
  177. uint32_t cmdreg;
  178. uint64_t reg;
  179. /* CFE will assign PCI resources */
  180. pci_probe_only = 1;
  181. /* Avoid ISA compat ranges. */
  182. PCIBIOS_MIN_IO = 0x00008000UL;
  183. PCIBIOS_MIN_MEM = 0x01000000UL;
  184. /* Set I/O resource limits. */
  185. ioport_resource.end = 0x01ffffffUL; /* 32MB accessible by sb1250 */
  186. iomem_resource.end = 0xffffffffUL; /* no HT support yet */
  187. cfg_space =
  188. ioremap(A_PHYS_LDTPCI_CFG_MATCH_BITS, 16 * 1024 * 1024);
  189. /*
  190. * See if the PCI bus has been configured by the firmware.
  191. */
  192. reg = __raw_readq(IOADDR(A_SCD_SYSTEM_CFG));
  193. if (!(reg & M_SYS_PCI_HOST)) {
  194. sb1250_bus_status |= PCI_DEVICE_MODE;
  195. } else {
  196. cmdreg =
  197. READCFG32(CFGOFFSET
  198. (0, PCI_DEVFN(PCI_BRIDGE_DEVICE, 0),
  199. PCI_COMMAND));
  200. if (!(cmdreg & PCI_COMMAND_MASTER)) {
  201. printk
  202. ("PCI: Skipping PCI probe. Bus is not initialized.\n");
  203. iounmap(cfg_space);
  204. return 0;
  205. }
  206. sb1250_bus_status |= PCI_BUS_ENABLED;
  207. }
  208. /*
  209. * Establish mappings in KSEG2 (kernel virtual) to PCI I/O
  210. * space. Use "match bytes" policy to make everything look
  211. * little-endian. So, you need to also set
  212. * CONFIG_SWAP_IO_SPACE, but this is the combination that
  213. * works correctly with most of Linux's drivers.
  214. * XXX ehs: Should this happen in PCI Device mode?
  215. */
  216. io_map_base = ioremap(A_PHYS_LDTPCI_IO_MATCH_BYTES, 1024 * 1024);
  217. sb1250_controller.io_map_base = io_map_base;
  218. set_io_port_base((unsigned long)io_map_base);
  219. #ifdef CONFIG_SIBYTE_HAS_LDT
  220. /*
  221. * Also check the LDT bridge's enable, just in case we didn't
  222. * initialize that one.
  223. */
  224. cmdreg = READCFG32(CFGOFFSET(0, PCI_DEVFN(LDT_BRIDGE_DEVICE, 0),
  225. PCI_COMMAND));
  226. if (cmdreg & PCI_COMMAND_MASTER) {
  227. sb1250_bus_status |= LDT_BUS_ENABLED;
  228. /*
  229. * Need bits 23:16 to convey vector number. Note that
  230. * this consumes 4MB of kernel-mapped memory
  231. * (Kseg2/Kseg3) for 32-bit kernel.
  232. */
  233. ldt_eoi_space = (unsigned long)
  234. ioremap(A_PHYS_LDT_SPECIAL_MATCH_BYTES,
  235. 4 * 1024 * 1024);
  236. }
  237. #endif
  238. register_pci_controller(&sb1250_controller);
  239. #ifdef CONFIG_VGA_CONSOLE
  240. take_over_console(&vga_con, 0, MAX_NR_CONSOLES - 1, 1);
  241. #endif
  242. return 0;
  243. }
  244. arch_initcall(sb1250_pcibios_init);