chrp_pci.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * CHRP pci routines.
  3. */
  4. #include <linux/config.h>
  5. #include <linux/kernel.h>
  6. #include <linux/pci.h>
  7. #include <linux/delay.h>
  8. #include <linux/string.h>
  9. #include <linux/init.h>
  10. #include <linux/ide.h>
  11. #include <linux/bootmem.h>
  12. #include <asm/io.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/irq.h>
  15. #include <asm/hydra.h>
  16. #include <asm/prom.h>
  17. #include <asm/gg2.h>
  18. #include <asm/machdep.h>
  19. #include <asm/sections.h>
  20. #include <asm/pci-bridge.h>
  21. #include <asm/open_pic.h>
  22. /* LongTrail */
  23. void __iomem *gg2_pci_config_base;
  24. /*
  25. * The VLSI Golden Gate II has only 512K of PCI configuration space, so we
  26. * limit the bus number to 3 bits
  27. */
  28. int __chrp gg2_read_config(struct pci_bus *bus, unsigned int devfn, int off,
  29. int len, u32 *val)
  30. {
  31. volatile void __iomem *cfg_data;
  32. struct pci_controller *hose = bus->sysdata;
  33. if (bus->number > 7)
  34. return PCIBIOS_DEVICE_NOT_FOUND;
  35. /*
  36. * Note: the caller has already checked that off is
  37. * suitably aligned and that len is 1, 2 or 4.
  38. */
  39. cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);
  40. switch (len) {
  41. case 1:
  42. *val = in_8(cfg_data);
  43. break;
  44. case 2:
  45. *val = in_le16(cfg_data);
  46. break;
  47. default:
  48. *val = in_le32(cfg_data);
  49. break;
  50. }
  51. return PCIBIOS_SUCCESSFUL;
  52. }
  53. int __chrp gg2_write_config(struct pci_bus *bus, unsigned int devfn, int off,
  54. int len, u32 val)
  55. {
  56. volatile void __iomem *cfg_data;
  57. struct pci_controller *hose = bus->sysdata;
  58. if (bus->number > 7)
  59. return PCIBIOS_DEVICE_NOT_FOUND;
  60. /*
  61. * Note: the caller has already checked that off is
  62. * suitably aligned and that len is 1, 2 or 4.
  63. */
  64. cfg_data = hose->cfg_data + ((bus->number<<16) | (devfn<<8) | off);
  65. switch (len) {
  66. case 1:
  67. out_8(cfg_data, val);
  68. break;
  69. case 2:
  70. out_le16(cfg_data, val);
  71. break;
  72. default:
  73. out_le32(cfg_data, val);
  74. break;
  75. }
  76. return PCIBIOS_SUCCESSFUL;
  77. }
  78. static struct pci_ops gg2_pci_ops =
  79. {
  80. gg2_read_config,
  81. gg2_write_config
  82. };
  83. /*
  84. * Access functions for PCI config space using RTAS calls.
  85. */
  86. int __chrp
  87. rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  88. int len, u32 *val)
  89. {
  90. struct pci_controller *hose = bus->sysdata;
  91. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  92. | (((bus->number - hose->first_busno) & 0xff) << 16)
  93. | (hose->index << 24);
  94. unsigned long ret = ~0UL;
  95. int rval;
  96. rval = call_rtas("read-pci-config", 2, 2, &ret, addr, len);
  97. *val = ret;
  98. return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
  99. }
  100. int __chrp
  101. rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  102. int len, u32 val)
  103. {
  104. struct pci_controller *hose = bus->sysdata;
  105. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  106. | (((bus->number - hose->first_busno) & 0xff) << 16)
  107. | (hose->index << 24);
  108. int rval;
  109. rval = call_rtas("write-pci-config", 3, 1, NULL, addr, len, val);
  110. return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
  111. }
  112. static struct pci_ops rtas_pci_ops =
  113. {
  114. rtas_read_config,
  115. rtas_write_config
  116. };
  117. volatile struct Hydra __iomem *Hydra = NULL;
  118. int __init
  119. hydra_init(void)
  120. {
  121. struct device_node *np;
  122. np = find_devices("mac-io");
  123. if (np == NULL || np->n_addrs == 0)
  124. return 0;
  125. Hydra = ioremap(np->addrs[0].address, np->addrs[0].size);
  126. printk("Hydra Mac I/O at %x\n", np->addrs[0].address);
  127. printk("Hydra Feature_Control was %x",
  128. in_le32(&Hydra->Feature_Control));
  129. out_le32(&Hydra->Feature_Control, (HYDRA_FC_SCC_CELL_EN |
  130. HYDRA_FC_SCSI_CELL_EN |
  131. HYDRA_FC_SCCA_ENABLE |
  132. HYDRA_FC_SCCB_ENABLE |
  133. HYDRA_FC_ARB_BYPASS |
  134. HYDRA_FC_MPIC_ENABLE |
  135. HYDRA_FC_SLOW_SCC_PCLK |
  136. HYDRA_FC_MPIC_IS_MASTER));
  137. printk(", now %x\n", in_le32(&Hydra->Feature_Control));
  138. return 1;
  139. }
  140. void __init
  141. chrp_pcibios_fixup(void)
  142. {
  143. struct pci_dev *dev = NULL;
  144. struct device_node *np;
  145. /* PCI interrupts are controlled by the OpenPIC */
  146. for_each_pci_dev(dev) {
  147. np = pci_device_to_OF_node(dev);
  148. if ((np != 0) && (np->n_intrs > 0) && (np->intrs[0].line != 0))
  149. dev->irq = np->intrs[0].line;
  150. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  151. }
  152. }
  153. #define PRG_CL_RESET_VALID 0x00010000
  154. static void __init
  155. setup_python(struct pci_controller *hose, struct device_node *dev)
  156. {
  157. u32 __iomem *reg;
  158. u32 val;
  159. unsigned long addr = dev->addrs[0].address;
  160. setup_indirect_pci(hose, addr + 0xf8000, addr + 0xf8010);
  161. /* Clear the magic go-slow bit */
  162. reg = ioremap(dev->addrs[0].address + 0xf6000, 0x40);
  163. val = in_be32(&reg[12]);
  164. if (val & PRG_CL_RESET_VALID) {
  165. out_be32(&reg[12], val & ~PRG_CL_RESET_VALID);
  166. in_be32(&reg[12]);
  167. }
  168. iounmap(reg);
  169. }
  170. /* Marvell Discovery II based Pegasos 2 */
  171. static void __init setup_peg2(struct pci_controller *hose, struct device_node *dev)
  172. {
  173. struct device_node *root = find_path_device("/");
  174. struct device_node *rtas;
  175. rtas = of_find_node_by_name (root, "rtas");
  176. if (rtas) {
  177. hose->ops = &rtas_pci_ops;
  178. } else {
  179. printk ("RTAS supporting Pegasos OF not found, please upgrade"
  180. " your firmware\n");
  181. }
  182. pci_assign_all_busses = 1;
  183. }
  184. void __init
  185. chrp_find_bridges(void)
  186. {
  187. struct device_node *dev;
  188. int *bus_range;
  189. int len, index = -1;
  190. struct pci_controller *hose;
  191. unsigned int *dma;
  192. char *model, *machine;
  193. int is_longtrail = 0, is_mot = 0, is_pegasos = 0;
  194. struct device_node *root = find_path_device("/");
  195. /*
  196. * The PCI host bridge nodes on some machines don't have
  197. * properties to adequately identify them, so we have to
  198. * look at what sort of machine this is as well.
  199. */
  200. machine = get_property(root, "model", NULL);
  201. if (machine != NULL) {
  202. is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;
  203. is_mot = strncmp(machine, "MOT", 3) == 0;
  204. if (strncmp(machine, "Pegasos2", 8) == 0)
  205. is_pegasos = 2;
  206. else if (strncmp(machine, "Pegasos", 7) == 0)
  207. is_pegasos = 1;
  208. }
  209. for (dev = root->child; dev != NULL; dev = dev->sibling) {
  210. if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
  211. continue;
  212. ++index;
  213. /* The GG2 bridge on the LongTrail doesn't have an address */
  214. if (dev->n_addrs < 1 && !is_longtrail) {
  215. printk(KERN_WARNING "Can't use %s: no address\n",
  216. dev->full_name);
  217. continue;
  218. }
  219. bus_range = (int *) get_property(dev, "bus-range", &len);
  220. if (bus_range == NULL || len < 2 * sizeof(int)) {
  221. printk(KERN_WARNING "Can't get bus-range for %s\n",
  222. dev->full_name);
  223. continue;
  224. }
  225. if (bus_range[1] == bus_range[0])
  226. printk(KERN_INFO "PCI bus %d", bus_range[0]);
  227. else
  228. printk(KERN_INFO "PCI buses %d..%d",
  229. bus_range[0], bus_range[1]);
  230. printk(" controlled by %s", dev->type);
  231. if (dev->n_addrs > 0)
  232. printk(" at %x", dev->addrs[0].address);
  233. printk("\n");
  234. hose = pcibios_alloc_controller();
  235. if (!hose) {
  236. printk("Can't allocate PCI controller structure for %s\n",
  237. dev->full_name);
  238. continue;
  239. }
  240. hose->arch_data = dev;
  241. hose->first_busno = bus_range[0];
  242. hose->last_busno = bus_range[1];
  243. model = get_property(dev, "model", NULL);
  244. if (model == NULL)
  245. model = "<none>";
  246. if (device_is_compatible(dev, "IBM,python")) {
  247. setup_python(hose, dev);
  248. } else if (is_mot
  249. || strncmp(model, "Motorola, Grackle", 17) == 0) {
  250. setup_grackle(hose);
  251. } else if (is_longtrail) {
  252. void __iomem *p = ioremap(GG2_PCI_CONFIG_BASE, 0x80000);
  253. hose->ops = &gg2_pci_ops;
  254. hose->cfg_data = p;
  255. gg2_pci_config_base = p;
  256. } else if (is_pegasos == 1) {
  257. setup_indirect_pci(hose, 0xfec00cf8, 0xfee00cfc);
  258. } else if (is_pegasos == 2) {
  259. setup_peg2(hose, dev);
  260. } else {
  261. printk("No methods for %s (model %s), using RTAS\n",
  262. dev->full_name, model);
  263. hose->ops = &rtas_pci_ops;
  264. }
  265. pci_process_bridge_OF_ranges(hose, dev, index == 0);
  266. /* check the first bridge for a property that we can
  267. use to set pci_dram_offset */
  268. dma = (unsigned int *)
  269. get_property(dev, "ibm,dma-ranges", &len);
  270. if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) {
  271. pci_dram_offset = dma[2] - dma[3];
  272. printk("pci_dram_offset = %lx\n", pci_dram_offset);
  273. }
  274. }
  275. /* Do not fixup interrupts from OF tree on pegasos */
  276. if (is_pegasos == 0)
  277. ppc_md.pcibios_fixup = chrp_pcibios_fixup;
  278. }