pci.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 <asm/io.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/irq.h>
  12. #include <asm/hydra.h>
  13. #include <asm/prom.h>
  14. #include <asm/machdep.h>
  15. #include <asm/sections.h>
  16. #include <asm/pci-bridge.h>
  17. #include <asm/grackle.h>
  18. #include <asm/rtas.h>
  19. #include "chrp.h"
  20. #include "gg2.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 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 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. .read = gg2_read_config,
  80. .write = gg2_write_config,
  81. };
  82. /*
  83. * Access functions for PCI config space using RTAS calls.
  84. */
  85. int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  86. int len, u32 *val)
  87. {
  88. struct pci_controller *hose = bus->sysdata;
  89. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  90. | (((bus->number - hose->first_busno) & 0xff) << 16)
  91. | (hose->global_number << 24);
  92. int ret = -1;
  93. int rval;
  94. rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
  95. *val = ret;
  96. return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
  97. }
  98. int rtas_write_config(struct pci_bus *bus, unsigned int devfn, int offset,
  99. int len, u32 val)
  100. {
  101. struct pci_controller *hose = bus->sysdata;
  102. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  103. | (((bus->number - hose->first_busno) & 0xff) << 16)
  104. | (hose->global_number << 24);
  105. int rval;
  106. rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
  107. addr, len, val);
  108. return rval? PCIBIOS_DEVICE_NOT_FOUND: PCIBIOS_SUCCESSFUL;
  109. }
  110. static struct pci_ops rtas_pci_ops =
  111. {
  112. .read = rtas_read_config,
  113. .write = rtas_write_config,
  114. };
  115. volatile struct Hydra __iomem *Hydra = NULL;
  116. int __init
  117. hydra_init(void)
  118. {
  119. struct device_node *np;
  120. struct resource r;
  121. np = of_find_node_by_name(NULL, "mac-io");
  122. if (np == NULL || of_address_to_resource(np, 0, &r)) {
  123. of_node_put(np);
  124. return 0;
  125. }
  126. Hydra = ioremap(r.start, r.end-r.start);
  127. printk("Hydra Mac I/O at %llx\n", (unsigned long long)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. #define PRG_CL_RESET_VALID 0x00010000
  142. static void __init
  143. setup_python(struct pci_controller *hose, struct device_node *dev)
  144. {
  145. u32 __iomem *reg;
  146. u32 val;
  147. struct resource r;
  148. if (of_address_to_resource(dev, 0, &r)) {
  149. printk(KERN_ERR "No address for Python PCI controller\n");
  150. return;
  151. }
  152. /* Clear the magic go-slow bit */
  153. reg = ioremap(r.start + 0xf6000, 0x40);
  154. BUG_ON(!reg);
  155. val = in_be32(&reg[12]);
  156. if (val & PRG_CL_RESET_VALID) {
  157. out_be32(&reg[12], val & ~PRG_CL_RESET_VALID);
  158. in_be32(&reg[12]);
  159. }
  160. iounmap(reg);
  161. setup_indirect_pci(hose, r.start + 0xf8000, r.start + 0xf8010, 0);
  162. }
  163. /* Marvell Discovery II based Pegasos 2 */
  164. static void __init setup_peg2(struct pci_controller *hose, struct device_node *dev)
  165. {
  166. struct device_node *root = of_find_node_by_path("/");
  167. struct device_node *rtas;
  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. /* keep the reference to the root node */
  178. }
  179. void __init
  180. chrp_find_bridges(void)
  181. {
  182. struct device_node *dev;
  183. const int *bus_range;
  184. int len, index = -1;
  185. struct pci_controller *hose;
  186. const unsigned int *dma;
  187. const char *model, *machine;
  188. int is_longtrail = 0, is_mot = 0, is_pegasos = 0;
  189. struct device_node *root = of_find_node_by_path("/");
  190. struct resource r;
  191. /*
  192. * The PCI host bridge nodes on some machines don't have
  193. * properties to adequately identify them, so we have to
  194. * look at what sort of machine this is as well.
  195. */
  196. machine = of_get_property(root, "model", NULL);
  197. if (machine != NULL) {
  198. is_longtrail = strncmp(machine, "IBM,LongTrail", 13) == 0;
  199. is_mot = strncmp(machine, "MOT", 3) == 0;
  200. if (strncmp(machine, "Pegasos2", 8) == 0)
  201. is_pegasos = 2;
  202. else if (strncmp(machine, "Pegasos", 7) == 0)
  203. is_pegasos = 1;
  204. }
  205. for (dev = root->child; dev != NULL; dev = dev->sibling) {
  206. if (dev->type == NULL || strcmp(dev->type, "pci") != 0)
  207. continue;
  208. ++index;
  209. /* The GG2 bridge on the LongTrail doesn't have an address */
  210. if (of_address_to_resource(dev, 0, &r) && !is_longtrail) {
  211. printk(KERN_WARNING "Can't use %s: no address\n",
  212. dev->full_name);
  213. continue;
  214. }
  215. bus_range = of_get_property(dev, "bus-range", &len);
  216. if (bus_range == NULL || len < 2 * sizeof(int)) {
  217. printk(KERN_WARNING "Can't get bus-range for %s\n",
  218. dev->full_name);
  219. continue;
  220. }
  221. if (bus_range[1] == bus_range[0])
  222. printk(KERN_INFO "PCI bus %d", bus_range[0]);
  223. else
  224. printk(KERN_INFO "PCI buses %d..%d",
  225. bus_range[0], bus_range[1]);
  226. printk(" controlled by %s", dev->full_name);
  227. if (!is_longtrail)
  228. printk(" at %llx", (unsigned long long)r.start);
  229. printk("\n");
  230. hose = pcibios_alloc_controller(dev);
  231. if (!hose) {
  232. printk("Can't allocate PCI controller structure for %s\n",
  233. dev->full_name);
  234. continue;
  235. }
  236. hose->first_busno = bus_range[0];
  237. hose->last_busno = bus_range[1];
  238. model = of_get_property(dev, "model", NULL);
  239. if (model == NULL)
  240. model = "<none>";
  241. if (of_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, 0);
  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. 0);
  260. if (index == 0) {
  261. dma = of_get_property(dev, "system-dma-base",
  262. &len);
  263. if (dma && len >= sizeof(*dma)) {
  264. dma = (unsigned int *)
  265. (((unsigned long)dma) +
  266. len - sizeof(*dma));
  267. pci_dram_offset = *dma;
  268. }
  269. }
  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 = of_get_property(dev, "ibm,dma-ranges", &len);
  279. if (index == 0 && dma != NULL && len >= 6 * sizeof(*dma)) {
  280. pci_dram_offset = dma[2] - dma[3];
  281. printk("pci_dram_offset = %lx\n", pci_dram_offset);
  282. }
  283. }
  284. of_node_put(root);
  285. }
  286. /* SL82C105 IDE Control/Status Register */
  287. #define SL82C105_IDECSR 0x40
  288. /* Fixup for Winbond ATA quirk, required for briq mostly because the
  289. * 8259 is configured for level sensitive IRQ 14 and so wants the
  290. * ATA controller to be set to fully native mode or bad things
  291. * will happen.
  292. */
  293. static void __devinit chrp_pci_fixup_winbond_ata(struct pci_dev *sl82c105)
  294. {
  295. u8 progif;
  296. /* If non-briq machines need that fixup too, please speak up */
  297. if (!machine_is(chrp) || _chrp_type != _CHRP_briq)
  298. return;
  299. if ((sl82c105->class & 5) != 5) {
  300. printk("W83C553: Switching SL82C105 IDE to PCI native mode\n");
  301. /* Enable SL82C105 PCI native IDE mode */
  302. pci_read_config_byte(sl82c105, PCI_CLASS_PROG, &progif);
  303. pci_write_config_byte(sl82c105, PCI_CLASS_PROG, progif | 0x05);
  304. sl82c105->class |= 0x05;
  305. /* Disable SL82C105 second port */
  306. pci_write_config_word(sl82c105, SL82C105_IDECSR, 0x0003);
  307. /* Clear IO BARs, they will be reassigned */
  308. pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_0, 0);
  309. pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_1, 0);
  310. pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_2, 0);
  311. pci_write_config_dword(sl82c105, PCI_BASE_ADDRESS_3, 0);
  312. }
  313. }
  314. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105,
  315. chrp_pci_fixup_winbond_ata);
  316. /* Pegasos2 firmware version 20040810 configures the built-in IDE controller
  317. * in legacy mode, but sets the PCI registers to PCI native mode.
  318. * The chip can only operate in legacy mode, so force the PCI class into legacy
  319. * mode as well. The same fixup must be done to the class-code property in
  320. * the IDE node /pci@80000000/ide@C,1
  321. */
  322. static void __devinit chrp_pci_fixup_vt8231_ata(struct pci_dev *viaide)
  323. {
  324. u8 progif;
  325. struct pci_dev *viaisa;
  326. if (!machine_is(chrp) || _chrp_type != _CHRP_Pegasos)
  327. return;
  328. if (viaide->irq != 14)
  329. return;
  330. viaisa = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL);
  331. if (!viaisa)
  332. return;
  333. printk("Fixing VIA IDE, force legacy mode on '%s'\n", viaide->dev.bus_id);
  334. pci_read_config_byte(viaide, PCI_CLASS_PROG, &progif);
  335. pci_write_config_byte(viaide, PCI_CLASS_PROG, progif & ~0x5);
  336. viaide->class &= ~0x5;
  337. pci_dev_put(viaisa);
  338. }
  339. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1, chrp_pci_fixup_vt8231_ata);