pci.c 8.1 KB

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