efika-pci.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include <linux/kernel.h>
  2. #include <linux/pci.h>
  3. #include <linux/string.h>
  4. #include <linux/init.h>
  5. #include <asm/io.h>
  6. #include <asm/irq.h>
  7. #include <asm/prom.h>
  8. #include <asm/machdep.h>
  9. #include <asm/sections.h>
  10. #include <asm/pci-bridge.h>
  11. #include <asm/rtas.h>
  12. #include "efika.h"
  13. #ifdef CONFIG_PCI
  14. /*
  15. * Access functions for PCI config space using RTAS calls.
  16. */
  17. static int rtas_read_config(struct pci_bus *bus, unsigned int devfn, int offset,
  18. int len, u32 * val)
  19. {
  20. struct pci_controller *hose = bus->sysdata;
  21. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  22. | (((bus->number - hose->first_busno) & 0xff) << 16)
  23. | (hose->index << 24);
  24. int ret = -1;
  25. int rval;
  26. rval = rtas_call(rtas_token("read-pci-config"), 2, 2, &ret, addr, len);
  27. *val = ret;
  28. return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  29. }
  30. static int rtas_write_config(struct pci_bus *bus, unsigned int devfn,
  31. int offset, int len, u32 val)
  32. {
  33. struct pci_controller *hose = bus->sysdata;
  34. unsigned long addr = (offset & 0xff) | ((devfn & 0xff) << 8)
  35. | (((bus->number - hose->first_busno) & 0xff) << 16)
  36. | (hose->index << 24);
  37. int rval;
  38. rval = rtas_call(rtas_token("write-pci-config"), 3, 1, NULL,
  39. addr, len, val);
  40. return rval ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  41. }
  42. static struct pci_ops rtas_pci_ops = {
  43. rtas_read_config,
  44. rtas_write_config
  45. };
  46. void __init efika_pcisetup(void)
  47. {
  48. const int *bus_range;
  49. int len;
  50. struct pci_controller *hose;
  51. struct device_node *root;
  52. struct device_node *pcictrl;
  53. root = of_find_node_by_path("/");
  54. if (root == NULL) {
  55. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  56. ": Unable to find the root node\n");
  57. return;
  58. }
  59. for (pcictrl = NULL;;) {
  60. pcictrl = of_get_next_child(root, pcictrl);
  61. if ((pcictrl == NULL) || (strcmp(pcictrl->name, "pci") == 0))
  62. break;
  63. }
  64. of_node_put(root);
  65. if (pcictrl == NULL) {
  66. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  67. ": Unable to find the PCI bridge node\n");
  68. return;
  69. }
  70. bus_range = get_property(pcictrl, "bus-range", &len);
  71. if (bus_range == NULL || len < 2 * sizeof(int)) {
  72. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  73. ": Can't get bus-range for %s\n", pcictrl->full_name);
  74. return;
  75. }
  76. if (bus_range[1] == bus_range[0])
  77. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI bus %d",
  78. bus_range[0]);
  79. else
  80. printk(KERN_INFO EFIKA_PLATFORM_NAME ": PCI buses %d..%d",
  81. bus_range[0], bus_range[1]);
  82. printk(" controlled by %s\n", pcictrl->full_name);
  83. printk("\n");
  84. hose = pcibios_alloc_controller();
  85. if (!hose) {
  86. printk(KERN_WARNING EFIKA_PLATFORM_NAME
  87. ": Can't allocate PCI controller structure for %s\n",
  88. pcictrl->full_name);
  89. return;
  90. }
  91. hose->arch_data = of_node_get(pcictrl);
  92. hose->first_busno = bus_range[0];
  93. hose->last_busno = bus_range[1];
  94. hose->ops = &rtas_pci_ops;
  95. pci_process_bridge_OF_ranges(hose, pcictrl, 0);
  96. }
  97. #else
  98. void __init efika_pcisetup(void)
  99. {}
  100. #endif