pci.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* arch/sh/kernel/pci.c
  2. * $Id: pci.c,v 1.1 2003/08/24 19:15:45 lethal Exp $
  3. *
  4. * Copyright (c) 2002 M. R. Brown <mrbrown@linux-sh.org>
  5. *
  6. *
  7. * These functions are collected here to reduce duplication of common
  8. * code amongst the many platform-specific PCI support code files.
  9. *
  10. * These routines require the following board-specific routines:
  11. * void pcibios_fixup_irqs();
  12. *
  13. * See include/asm-sh/pci.h for more information.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/pci.h>
  17. #include <linux/init.h>
  18. static int __init pcibios_init(void)
  19. {
  20. struct pci_channel *p;
  21. struct pci_bus *bus;
  22. int busno;
  23. #ifdef CONFIG_PCI_AUTO
  24. /* assign resources */
  25. busno = 0;
  26. for (p = board_pci_channels; p->pci_ops != NULL; p++) {
  27. busno = pciauto_assign_resources(busno, p) + 1;
  28. }
  29. #endif
  30. /* scan the buses */
  31. busno = 0;
  32. for (p= board_pci_channels; p->pci_ops != NULL; p++) {
  33. bus = pci_scan_bus(busno, p->pci_ops, p);
  34. busno = bus->subordinate+1;
  35. }
  36. /* board-specific fixups */
  37. pcibios_fixup_irqs();
  38. return 0;
  39. }
  40. subsys_initcall(pcibios_init);
  41. void
  42. pcibios_update_resource(struct pci_dev *dev, struct resource *root,
  43. struct resource *res, int resource)
  44. {
  45. u32 new, check;
  46. int reg;
  47. new = res->start | (res->flags & PCI_REGION_FLAG_MASK);
  48. if (resource < 6) {
  49. reg = PCI_BASE_ADDRESS_0 + 4*resource;
  50. } else if (resource == PCI_ROM_RESOURCE) {
  51. res->flags |= IORESOURCE_ROM_ENABLE;
  52. new |= PCI_ROM_ADDRESS_ENABLE;
  53. reg = dev->rom_base_reg;
  54. } else {
  55. /* Somebody might have asked allocation of a non-standard resource */
  56. return;
  57. }
  58. pci_write_config_dword(dev, reg, new);
  59. pci_read_config_dword(dev, reg, &check);
  60. if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) {
  61. printk(KERN_ERR "PCI: Error while updating region "
  62. "%s/%d (%08x != %08x)\n", pci_name(dev), resource,
  63. new, check);
  64. }
  65. }
  66. void pcibios_align_resource(void *data, struct resource *res,
  67. unsigned long size, unsigned long align)
  68. __attribute__ ((weak));
  69. /*
  70. * We need to avoid collisions with `mirrored' VGA ports
  71. * and other strange ISA hardware, so we always want the
  72. * addresses to be allocated in the 0x000-0x0ff region
  73. * modulo 0x400.
  74. */
  75. void pcibios_align_resource(void *data, struct resource *res,
  76. unsigned long size, unsigned long align)
  77. {
  78. if (res->flags & IORESOURCE_IO) {
  79. unsigned long start = res->start;
  80. if (start & 0x300) {
  81. start = (start + 0x3ff) & ~0x3ff;
  82. res->start = start;
  83. }
  84. }
  85. }
  86. int pcibios_enable_device(struct pci_dev *dev, int mask)
  87. {
  88. u16 cmd, old_cmd;
  89. int idx;
  90. struct resource *r;
  91. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  92. old_cmd = cmd;
  93. for(idx=0; idx<6; idx++) {
  94. if (!(mask & (1 << idx)))
  95. continue;
  96. r = &dev->resource[idx];
  97. if (!r->start && r->end) {
  98. printk(KERN_ERR "PCI: Device %s not available because "
  99. "of resource collisions\n", pci_name(dev));
  100. return -EINVAL;
  101. }
  102. if (r->flags & IORESOURCE_IO)
  103. cmd |= PCI_COMMAND_IO;
  104. if (r->flags & IORESOURCE_MEM)
  105. cmd |= PCI_COMMAND_MEMORY;
  106. }
  107. if (dev->resource[PCI_ROM_RESOURCE].start)
  108. cmd |= PCI_COMMAND_MEMORY;
  109. if (cmd != old_cmd) {
  110. printk(KERN_INFO "PCI: Enabling device %s (%04x -> %04x)\n",
  111. pci_name(dev), old_cmd, cmd);
  112. pci_write_config_word(dev, PCI_COMMAND, cmd);
  113. }
  114. return 0;
  115. }
  116. /*
  117. * If we set up a device for bus mastering, we need to check and set
  118. * the latency timer as it may not be properly set.
  119. */
  120. unsigned int pcibios_max_latency = 255;
  121. void pcibios_set_master(struct pci_dev *dev)
  122. {
  123. u8 lat;
  124. pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
  125. if (lat < 16)
  126. lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
  127. else if (lat > pcibios_max_latency)
  128. lat = pcibios_max_latency;
  129. else
  130. return;
  131. printk(KERN_INFO "PCI: Setting latency timer of device %s to %d\n", pci_name(dev), lat);
  132. pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
  133. }
  134. void __init pcibios_update_irq(struct pci_dev *dev, int irq)
  135. {
  136. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  137. }