pci-bcm1480ht.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2001,2002,2005 Broadcom Corporation
  4. * Copyright (C) 2004 by Ralf Baechle ([email protected])
  5. */
  6. /*
  7. * BCM1480/1455-specific HT support (looking like PCI)
  8. *
  9. * This module provides the glue between Linux's PCI subsystem
  10. * and the hardware. We basically provide glue for accessing
  11. * configuration space, and set up the translation for I/O
  12. * space accesses.
  13. *
  14. * To access configuration space, we use ioremap. In the 32-bit
  15. * kernel, this consumes either 4 or 8 page table pages, and 16MB of
  16. * kernel mapped memory. Hopefully neither of these should be a huge
  17. * problem.
  18. *
  19. */
  20. #include <linux/types.h>
  21. #include <linux/pci.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/mm.h>
  25. #include <linux/console.h>
  26. #include <linux/tty.h>
  27. #include <asm/sibyte/bcm1480_regs.h>
  28. #include <asm/sibyte/bcm1480_scd.h>
  29. #include <asm/sibyte/board.h>
  30. #include <asm/io.h>
  31. /*
  32. * Macros for calculating offsets into config space given a device
  33. * structure or dev/fun/reg
  34. */
  35. #define CFGOFFSET(bus, devfn, where) (((bus)<<16)+((devfn)<<8)+(where))
  36. #define CFGADDR(bus, devfn, where) CFGOFFSET((bus)->number, (devfn), where)
  37. static void *ht_cfg_space;
  38. #define PCI_BUS_ENABLED 1
  39. #define PCI_DEVICE_MODE 2
  40. static int bcm1480ht_bus_status;
  41. #define PCI_BRIDGE_DEVICE 0
  42. #define HT_BRIDGE_DEVICE 1
  43. /*
  44. * HT's level-sensitive interrupts require EOI, which is generated
  45. * through a 4MB memory-mapped region
  46. */
  47. unsigned long ht_eoi_space;
  48. /*
  49. * Read/write 32-bit values in config space.
  50. */
  51. static inline u32 READCFG32(u32 addr)
  52. {
  53. return *(u32 *)(ht_cfg_space + (addr&~3));
  54. }
  55. static inline void WRITECFG32(u32 addr, u32 data)
  56. {
  57. *(u32 *)(ht_cfg_space + (addr & ~3)) = data;
  58. }
  59. /*
  60. * Some checks before doing config cycles:
  61. * In PCI Device Mode, hide everything on bus 0 except the LDT host
  62. * bridge. Otherwise, access is controlled by bridge MasterEn bits.
  63. */
  64. static int bcm1480ht_can_access(struct pci_bus *bus, int devfn)
  65. {
  66. u32 devno;
  67. if (!(bcm1480ht_bus_status & (PCI_BUS_ENABLED | PCI_DEVICE_MODE)))
  68. return 0;
  69. if (bus->number == 0) {
  70. devno = PCI_SLOT(devfn);
  71. if (bcm1480ht_bus_status & PCI_DEVICE_MODE)
  72. return 0;
  73. }
  74. return 1;
  75. }
  76. /*
  77. * Read/write access functions for various sizes of values
  78. * in config space. Return all 1's for disallowed accesses
  79. * for a kludgy but adequate simulation of master aborts.
  80. */
  81. static int bcm1480ht_pcibios_read(struct pci_bus *bus, unsigned int devfn,
  82. int where, int size, u32 * val)
  83. {
  84. u32 data = 0;
  85. if ((size == 2) && (where & 1))
  86. return PCIBIOS_BAD_REGISTER_NUMBER;
  87. else if ((size == 4) && (where & 3))
  88. return PCIBIOS_BAD_REGISTER_NUMBER;
  89. if (bcm1480ht_can_access(bus, devfn))
  90. data = READCFG32(CFGADDR(bus, devfn, where));
  91. else
  92. data = 0xFFFFFFFF;
  93. if (size == 1)
  94. *val = (data >> ((where & 3) << 3)) & 0xff;
  95. else if (size == 2)
  96. *val = (data >> ((where & 3) << 3)) & 0xffff;
  97. else
  98. *val = data;
  99. return PCIBIOS_SUCCESSFUL;
  100. }
  101. static int bcm1480ht_pcibios_write(struct pci_bus *bus, unsigned int devfn,
  102. int where, int size, u32 val)
  103. {
  104. u32 cfgaddr = CFGADDR(bus, devfn, where);
  105. u32 data = 0;
  106. if ((size == 2) && (where & 1))
  107. return PCIBIOS_BAD_REGISTER_NUMBER;
  108. else if ((size == 4) && (where & 3))
  109. return PCIBIOS_BAD_REGISTER_NUMBER;
  110. if (!bcm1480ht_can_access(bus, devfn))
  111. return PCIBIOS_BAD_REGISTER_NUMBER;
  112. data = READCFG32(cfgaddr);
  113. if (size == 1)
  114. data = (data & ~(0xff << ((where & 3) << 3))) |
  115. (val << ((where & 3) << 3));
  116. else if (size == 2)
  117. data = (data & ~(0xffff << ((where & 3) << 3))) |
  118. (val << ((where & 3) << 3));
  119. else
  120. data = val;
  121. WRITECFG32(cfgaddr, data);
  122. return PCIBIOS_SUCCESSFUL;
  123. }
  124. static int bcm1480ht_pcibios_get_busno(void)
  125. {
  126. return 0;
  127. }
  128. struct pci_ops bcm1480ht_pci_ops = {
  129. .read = bcm1480ht_pcibios_read,
  130. .write = bcm1480ht_pcibios_write,
  131. };
  132. static struct resource bcm1480ht_mem_resource = {
  133. .name = "BCM1480 HT MEM",
  134. .start = A_BCM1480_PHYS_HT_MEM_MATCH_BYTES,
  135. .end = A_BCM1480_PHYS_HT_MEM_MATCH_BYTES + 0x1fffffffUL,
  136. .flags = IORESOURCE_MEM,
  137. };
  138. static struct resource bcm1480ht_io_resource = {
  139. .name = "BCM1480 HT I/O",
  140. .start = A_BCM1480_PHYS_HT_IO_MATCH_BYTES,
  141. .end = A_BCM1480_PHYS_HT_IO_MATCH_BYTES + 0x01ffffffUL,
  142. .flags = IORESOURCE_IO,
  143. };
  144. struct pci_controller bcm1480ht_controller = {
  145. .pci_ops = &bcm1480ht_pci_ops,
  146. .mem_resource = &bcm1480ht_mem_resource,
  147. .io_resource = &bcm1480ht_io_resource,
  148. .index = 1,
  149. .get_busno = bcm1480ht_pcibios_get_busno,
  150. .io_offset = A_BCM1480_PHYS_HT_IO_MATCH_BYTES,
  151. };
  152. static int __init bcm1480ht_pcibios_init(void)
  153. {
  154. ht_cfg_space = ioremap(A_BCM1480_PHYS_HT_CFG_MATCH_BITS, 16*1024*1024);
  155. /* CFE doesn't always init all HT paths, so we always scan */
  156. bcm1480ht_bus_status |= PCI_BUS_ENABLED;
  157. ht_eoi_space = (unsigned long)
  158. ioremap(A_BCM1480_PHYS_HT_SPECIAL_MATCH_BYTES,
  159. 4 * 1024 * 1024);
  160. bcm1480ht_controller.io_map_base = (unsigned long)
  161. ioremap(A_BCM1480_PHYS_HT_IO_MATCH_BYTES, 65536);
  162. bcm1480ht_controller.io_map_base -= bcm1480ht_controller.io_offset;
  163. register_pci_controller(&bcm1480ht_controller);
  164. return 0;
  165. }
  166. arch_initcall(bcm1480ht_pcibios_init);