pcibios.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * $Id: pcibios.c,v 1.1 2001/08/24 12:38:19 dwmw2 Exp $
  3.  *
  4.  * arch/sh/kernel/pcibios.c
  5.  *
  6.  * This is GPL'd.
  7.  *
  8.  * Provided here are generic versions of:
  9.  * pcibios_update_resource()
  10.  * pcibios_align_resource()
  11.  * pcibios_enable_device()
  12.  * pcibios_set_master()
  13.  * pcibios_update_irq()
  14.  *
  15.  * These functions are collected here to reduce duplication of common
  16.  * code amongst the many platform-specific PCI support code files.
  17.  *
  18.  * Platform-specific files are expected to provide:
  19.  * pcibios_fixup_bus()
  20.  * pcibios_init()
  21.  * pcibios_setup()
  22.  * pcibios_fixup_pbus_ranges()
  23.  */
  24. #include <linux/kernel.h>
  25. #include <linux/pci.h>
  26. #include <linux/init.h>
  27. void
  28. pcibios_update_resource(struct pci_dev *dev, struct resource *root,
  29. struct resource *res, int resource)
  30. {
  31. u32 new, check;
  32. int reg;
  33. new = res->start | (res->flags & PCI_REGION_FLAG_MASK);
  34. if (resource < 6) {
  35. reg = PCI_BASE_ADDRESS_0 + 4*resource;
  36. } else if (resource == PCI_ROM_RESOURCE) {
  37. res->flags |= PCI_ROM_ADDRESS_ENABLE;
  38. new |= PCI_ROM_ADDRESS_ENABLE;
  39. reg = dev->rom_base_reg;
  40. } else {
  41. /* Somebody might have asked allocation of a non-standard resource */
  42. return;
  43. }
  44. pci_write_config_dword(dev, reg, new);
  45. pci_read_config_dword(dev, reg, &check);
  46. if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) {
  47. printk(KERN_ERR "PCI: Error while updating region "
  48.        "%s/%d (%08x != %08x)n", dev->slot_name, resource,
  49.        new, check);
  50. }
  51. }
  52. /*
  53.  * We need to avoid collisions with `mirrored' VGA ports
  54.  * and other strange ISA hardware, so we always want the
  55.  * addresses to be allocated in the 0x000-0x0ff region
  56.  * modulo 0x400.
  57.  */
  58. void pcibios_align_resource(void *data, struct resource *res,
  59.     unsigned long size, unsigned long align)
  60. {
  61. if (res->flags & IORESOURCE_IO) {
  62. unsigned long start = res->start;
  63. if (start & 0x300) {
  64. start = (start + 0x3ff) & ~0x3ff;
  65. res->start = start;
  66. }
  67. }
  68. }
  69. int pcibios_enable_device(struct pci_dev *dev)
  70. {
  71. u16 cmd, old_cmd;
  72. int idx;
  73. struct resource *r;
  74. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  75. old_cmd = cmd;
  76. for(idx=0; idx<6; idx++) {
  77. r = &dev->resource[idx];
  78. if (!r->start && r->end) {
  79. printk(KERN_ERR "PCI: Device %s not available because of resource collisionsn", dev->slot_name);
  80. return -EINVAL;
  81. }
  82. if (r->flags & IORESOURCE_IO)
  83. cmd |= PCI_COMMAND_IO;
  84. if (r->flags & IORESOURCE_MEM)
  85. cmd |= PCI_COMMAND_MEMORY;
  86. }
  87. if (dev->resource[PCI_ROM_RESOURCE].start)
  88. cmd |= PCI_COMMAND_MEMORY;
  89. if (cmd != old_cmd) {
  90. printk(KERN_INFO "PCI: Enabling device %s (%04x -> %04x)n", dev->name, old_cmd, cmd);
  91. pci_write_config_word(dev, PCI_COMMAND, cmd);
  92. }
  93. return 0;
  94. }
  95. /*
  96.  *  If we set up a device for bus mastering, we need to check and set
  97.  *  the latency timer as it may not be properly set.
  98.  */
  99. unsigned int pcibios_max_latency = 255;
  100. void pcibios_set_master(struct pci_dev *dev)
  101. {
  102. u8 lat;
  103. pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
  104. if (lat < 16)
  105. lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
  106. else if (lat > pcibios_max_latency)
  107. lat = pcibios_max_latency;
  108. else
  109. return;
  110. printk(KERN_INFO "PCI: Setting latency timer of device %s to %dn", dev->name, lat);
  111. pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
  112. }
  113. void __init pcibios_update_irq(struct pci_dev *dev, int irq)
  114. {
  115. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  116. }