pci.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * CHRP pci routines.
  3. */
  4. #include <linux/kernel.h>
  5. #include <linux/pci.h>
  6. #include <linux/delay.h>
  7. #include <linux/string.h>
  8. #include <linux/init.h>
  9. #include <linux/ide.h>
  10. #include <asm/io.h>
  11. #include <asm/pgtable.h>
  12. #include <asm/irq.h>
  13. #include <asm/hydra.h>
  14. #include <asm/prom.h>
  15. #include <asm/gg2.h>
  16. #include <asm/machdep.h>
  17. #include <asm/sections.h>
  18. #include <asm/pci-bridge.h>
  19. #include <asm/grackle.h>
  20. #include <asm/rtas.h>
  21. #include "chrp.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 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 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 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. int ret = -1;
  94. int rval;
  95. rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
  96. *val = ret;
  97. return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
  98. }
  99. int rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  100. int len, u32 val)
  101. {
  102. struct pci_controller *hose = bus->sysdata;
  103. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  104. | (((bus->number - hose->first_busno) & 0xff) << 16)
  105. | (hose->index << 24);
  106. int rval;
  107. rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
  108. 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. struct resource r;
  122. np = find_devices("mac-io");
  123. if (np == NULL || of_address_to_resource(np, 0, &r))
  124. return 0;
  125. Hydra = ioremap(r.start, r.end-r.start);
  126. printk("Hydra Mac I/O at %llx\n", (unsigned long long)r.start);
  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. #define PRG_CL_RESET_VALID 0x00010000
  141. static void __init
  142. setup_python(struct pci_controller *hose, struct device_node *dev)
  143. {
  144. u32 __iomem *reg;
  145. u32 val;
  146. struct resource r;
  147. if (of_address_to_resource(dev, 0, &r)) {
  148. printk(KERN_ERR "No address for Python PCI controller\n");
  149. return;
  150. }
  151. /* Clear the magic go-slow bit */
  152. reg = ioremap(r.start + 0xf6000, 0x40);
  153. BUG_ON(!reg);
  154. val = in_be32(&reg[12]);
  155. if (val & PRG_CL_RESET_VALID) {
  156. out_be32(&reg[12], val & ~PRG_CL_RESET_VALID);
  157. in_be32(&reg[12]);
  158. }
  159. iounmap(reg);
  160. setup_indirect_pci(hose, r.start + 0xf8000, r.start + 0xf8010);
  161. }
  162. /* Marvell Discovery II based Pegasos 2 */
  163. static void __init setup_peg2(struct pci_controller *hose, struct device_node *dev)
  164. {
  165. struct device_node *root = find_path_device("/");
  166. struct device_node *rtas;
  167. of_node_get(root);
  168. rtas = of_find_node_by_name (root, "rtas");
  169. if (rtas) {
  170. hose->ops = &rtas_pci_ops;
  171. of_node_put(rtas);
  172. } else {
  173. printk ("RTAS supporting Pegasos OF not found, please upgrade"
  174. " your firmware\n");
  175. }
  176. pci_assign_all_buses = 1;
  177. }
  178. void __init
  179. chrp_find_bridges(void)
  180. {
  181. struct device_node *dev;
  182. const int *bus_range;
  183. int len, index = -1;
  184. struct pci_controller *hose;
  185. const unsigned int *dma;
  186. const char *model, *machine;
  187. int is_longtrail = 0, is_mot = 0, is_pegasos = 0;
  188. struct device_node *root = find_path_device("/");
  189. struct resource r;
  190. /*
  191. * The PCI host bridge nodes on some machines don't have
  192. * properties to adequately identify them, so we have to
  193. * look at what sort of machine this is as well.
  194. */
  195. machine = get_property(root, "model", NULL);
  196. if (machine != NULL) {
  197. is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;
  198. is_mot = strncmp(machine, "MOT", 3) == 0;
  199. if (strncmp(machine, "Pegasos2", 8) == 0)
  200. is_pegasos = 2;
  201. else if (strncmp(machine, "Pegasos", 7) == 0)
  202. is_pegasos = 1;
  203. }
  204. for (dev = root->child; dev != NULL; dev = dev->sibling) {
  205. if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
  206. continue;
  207. ++index;
  208. /* The GG2 bridge on the LongTrail doesn't have an address */
  209. if (of_address_to_resource(dev, 0, &r) && !is_longtrail) {
  210. printk(KERN_WARNING "Can't use %s: no address\n",
  211. dev->full_name);
  212. continue;
  213. }
  214. bus_range = get_property(dev, "bus-range", &len);
  215. if (bus_range == NULL || len < 2 * sizeof(int)) {
  216. printk(KERN_WARNING "Can't get bus-range for %s\n",
  217. dev->full_name);
  218. continue;
  219. }
  220. if (bus_range[1] == bus_range[0])
  221. printk(KERN_INFO "PCI bus %d", bus_range[0]);
  222. else
  223. printk(KERN_INFO "PCI buses %d..%d",
  224. bus_range[0], bus_range[1]);
  225. printk(" controlled by %s", dev->full_name);
  226. if (!is_longtrail)
  227. printk(" at %llx", (unsigned long long)r.start);
  228. printk("\n");
  229. hose = pcibios_alloc_controller();
  230. if (!hose) {
  231. printk("Can't allocate PCI controller structure for %s\n",
  232. dev->full_name);
  233. continue;
  234. }
  235. hose->arch_data = dev;
  236. hose->first_busno = bus_range[0];
  237. hose->last_busno = bus_range[1];
  238. model = get_property(dev, "model", NULL);
  239. if (model == NULL)
  240. model = "<none>";
  241. if (device_is_compatible(dev, "IBM,python")) {
  242. setup_python(hose, dev);
  243. } else if (is_mot
  244. || strncmp(model, "Motorola, Grackle", 17) == 0) {
  245. setup_grackle(hose);
  246. } else if (is_longtrail) {
  247. void __iomem *p = ioremap(GG2_PCI_CONFIG_BASE, 0x80000);
  248. hose->ops = &gg2_pci_ops;
  249. hose->cfg_data = p;
  250. gg2_pci_config_base = p;
  251. } else if (is_pegasos == 1) {
  252. setup_indirect_pci(hose, 0xfec00cf8, 0xfee00cfc);
  253. } else if (is_pegasos == 2) {
  254. setup_peg2(hose, dev);
  255. } else if (!strncmp(model, "IBM,CPC710", 10)) {
  256. setup_indirect_pci(hose,
  257. r.start + 0x000f8000,
  258. r.start + 0x000f8010);
  259. if (index == 0) {
  260. dma = get_property(dev, "system-dma-base",&len);
  261. if (dma && len >= sizeof(*dma)) {
  262. dma = (unsigned int *)
  263. (((unsigned long)dma) +
  264. len - sizeof(*dma));
  265. pci_dram_offset = *dma;
  266. }
  267. }
  268. } else {
  269. printk("No methods for %s (model %s), using RTAS\n",
  270. dev->full_name, model);
  271. hose->ops = &rtas_pci_ops;
  272. }
  273. pci_process_bridge_OF_ranges(hose, dev, index == 0);
  274. /* check the first bridge for a property that we can
  275. use to set pci_dram_offset */
  276. dma = 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. }
  283. /* SL82C105 IDE Control/Status Register */
  284. #define SL82C105_IDECSR 0x40
  285. /* Fixup for Winbond ATA quirk, required for briq */
  286. void chrp_pci_fixup_winbond_ata(struct pci_dev *sl82c105)
  287. {
  288. u8 progif;
  289. /* If non-briq machines need that fixup too, please speak up */
  290. if (!machine_is(chrp) || _chrp_type != _CHRP_briq)
  291. return;
  292. if ((sl82c105->class & 5) != 5) {
  293. printk("W83C553: Switching SL82C105 IDE to PCI native mode\n");
  294. /* Enable SL82C105 PCI native IDE mode */
  295. pci_read_config_byte(sl82c105, PCI_CLASS_PROG, &progif);
  296. pci_write_config_byte(sl82c105, PCI_CLASS_PROG, progif | 0x05);
  297. sl82c105->class |= 0x05;
  298. /* Disable SL82C105 second port */
  299. pci_write_config_word(sl82c105, SL82C105_IDECSR, 0x0003);
  300. }
  301. }
  302. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105,
  303. chrp_pci_fixup_winbond_ata);