bios.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. prot = pgprot_val(vma->vm_page_prot);
  26. vma->vm_page_prot = __pgprot(prot);
  27. /* Write-combine setting is ignored, it is changed via the mtrr
  28. * interfaces on this platform.
  29. */
  30. if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  31. vma->vm_end - vma->vm_start,
  32. vma->vm_page_prot))
  33. return -EAGAIN;
  34. return 0;
  35. }
  36. void
  37. pcibios_align_resource(void *data, struct resource *res,
  38. resource_size_t size, resource_size_t align)
  39. {
  40. if (res->flags & IORESOURCE_IO) {
  41. resource_size_t start = res->start;
  42. if (start & 0x300) {
  43. start = (start + 0x3ff) & ~0x3ff;
  44. res->start = start;
  45. }
  46. }
  47. }
  48. int pcibios_enable_resources(struct pci_dev *dev, int mask)
  49. {
  50. u16 cmd, old_cmd;
  51. int idx;
  52. struct resource *r;
  53. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  54. old_cmd = cmd;
  55. for(idx=0; idx<6; idx++) {
  56. /* Only set up the requested stuff */
  57. if (!(mask & (1<<idx)))
  58. continue;
  59. r = &dev->resource[idx];
  60. if (!r->start && r->end) {
  61. printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
  62. return -EINVAL;
  63. }
  64. if (r->flags & IORESOURCE_IO)
  65. cmd |= PCI_COMMAND_IO;
  66. if (r->flags & IORESOURCE_MEM)
  67. cmd |= PCI_COMMAND_MEMORY;
  68. }
  69. if (dev->resource[PCI_ROM_RESOURCE].start)
  70. cmd |= PCI_COMMAND_MEMORY;
  71. if (cmd != old_cmd) {
  72. printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
  73. pci_write_config_word(dev, PCI_COMMAND, cmd);
  74. }
  75. return 0;
  76. }
  77. int pcibios_enable_irq(struct pci_dev *dev)
  78. {
  79. dev->irq = EXT_INTR_VECT;
  80. return 0;
  81. }
  82. int pcibios_enable_device(struct pci_dev *dev, int mask)
  83. {
  84. int err;
  85. if ((err = pcibios_enable_resources(dev, mask)) < 0)
  86. return err;
  87. return pcibios_enable_irq(dev);
  88. }
  89. int pcibios_assign_resources(void)
  90. {
  91. struct pci_dev *dev = NULL;
  92. int idx;
  93. struct resource *r;
  94. while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
  95. int class = dev->class >> 8;
  96. /* Don't touch classless devices and host bridges */
  97. if (!class || class == PCI_CLASS_BRIDGE_HOST)
  98. continue;
  99. for(idx=0; idx<6; idx++) {
  100. r = &dev->resource[idx];
  101. if (!r->start && r->end)
  102. pci_assign_resource(dev, idx);
  103. }
  104. }
  105. return 0;
  106. }
  107. EXPORT_SYMBOL(pcibios_assign_resources);