pci.c 8.0 KB

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