bios.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include <linux/pci.h>
  2. #include <linux/kernel.h>
  3. #include <asm/arch/hwregs/intr_vect.h>
  4. void __devinit pcibios_fixup_bus(struct pci_bus *b)
  5. {
  6. }
  7. char * __devinit pcibios_setup(char *str)
  8. {
  9. return NULL;
  10. }
  11. void pcibios_set_master(struct pci_dev *dev)
  12. {
  13. u8 lat;
  14. pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
  15. printk(KERN_DEBUG "PCI: Setting latency timer of device %s to %d\n", pci_name(dev), lat);
  16. pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
  17. }
  18. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  19. enum pci_mmap_state mmap_state, int write_combine)
  20. {
  21. unsigned long prot;
  22. /* Leave vm_pgoff as-is, the PCI space address is the physical
  23. * address on this platform.
  24. */
  25. vma->vm_flags |= (VM_SHM | VM_LOCKED | VM_IO);
  26. prot = pgprot_val(vma->vm_page_prot);
  27. vma->vm_page_prot = __pgprot(prot);
  28. /* Write-combine setting is ignored, it is changed via the mtrr
  29. * interfaces on this platform.
  30. */
  31. if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  32. vma->vm_end - vma->vm_start,
  33. vma->vm_page_prot))
  34. return -EAGAIN;
  35. return 0;
  36. }
  37. void
  38. pcibios_align_resource(void *data, struct resource *res,
  39. unsigned long size, unsigned long align)
  40. {
  41. if (res->flags & IORESOURCE_IO) {
  42. unsigned long start = res->start;
  43. if (start & 0x300) {
  44. start = (start + 0x3ff) & ~0x3ff;
  45. res->start = start;
  46. }
  47. }
  48. }
  49. int pcibios_enable_resources(struct pci_dev *dev, int mask)
  50. {
  51. u16 cmd, old_cmd;
  52. int idx;
  53. struct resource *r;
  54. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  55. old_cmd = cmd;
  56. for(idx=0; idx<6; idx++) {
  57. /* Only set up the requested stuff */
  58. if (!(mask & (1<<idx)))
  59. continue;
  60. r = &dev->resource[idx];
  61. if (!r->start && r->end) {
  62. printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
  63. return -EINVAL;
  64. }
  65. if (r->flags & IORESOURCE_IO)
  66. cmd |= PCI_COMMAND_IO;
  67. if (r->flags & IORESOURCE_MEM)
  68. cmd |= PCI_COMMAND_MEMORY;
  69. }
  70. if (dev->resource[PCI_ROM_RESOURCE].start)
  71. cmd |= PCI_COMMAND_MEMORY;
  72. if (cmd != old_cmd) {
  73. printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
  74. pci_write_config_word(dev, PCI_COMMAND, cmd);
  75. }
  76. return 0;
  77. }
  78. int pcibios_enable_irq(struct pci_dev *dev)
  79. {
  80. dev->irq = EXT_INTR_VECT;
  81. return 0;
  82. }
  83. int pcibios_enable_device(struct pci_dev *dev, int mask)
  84. {
  85. int err;
  86. if ((err = pcibios_enable_resources(dev, mask)) < 0)
  87. return err;
  88. return pcibios_enable_irq(dev);
  89. }
  90. int pcibios_assign_resources(void)
  91. {
  92. struct pci_dev *dev = NULL;
  93. int idx;
  94. struct resource *r;
  95. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  96. int class = dev->class >> 8;
  97. /* Don't touch classless devices and host bridges */
  98. if (!class || class == PCI_CLASS_BRIDGE_HOST)
  99. continue;
  100. for(idx=0; idx<6; idx++) {
  101. r = &dev->resource[idx];
  102. if (!r->start && r->end)
  103. pci_assign_resource(dev, idx);
  104. }
  105. }
  106. return 0;
  107. }
  108. EXPORT_SYMBOL(pcibios_assign_resources);