chrp_pci.c 7.9 KB

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