pci-sb1250.c 7.5 KB

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