pcibios.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * pci.c -- basic PCI support code
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * (C) Copyright 2011, Greg Ungerer <gerg@uclinux.org>
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/mm.h>
  14. #include <linux/init.h>
  15. #include <linux/pci.h>
  16. /*
  17. * From arch/i386/kernel/pci-i386.c:
  18. *
  19. * We need to avoid collisions with `mirrored' VGA ports
  20. * and other strange ISA hardware, so we always want the
  21. * addresses to be allocated in the 0x000-0x0ff region
  22. * modulo 0x400.
  23. *
  24. * Why? Because some silly external IO cards only decode
  25. * the low 10 bits of the IO address. The 0x00-0xff region
  26. * is reserved for motherboard devices that decode all 16
  27. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  28. * but we want to try to avoid allocating at 0x2900-0x2bff
  29. * which might be mirrored at 0x0100-0x03ff..
  30. */
  31. resource_size_t pcibios_align_resource(void *data, const struct resource *res,
  32. resource_size_t size, resource_size_t align)
  33. {
  34. resource_size_t start = res->start;
  35. if ((res->flags & IORESOURCE_IO) && (start & 0x300))
  36. start = (start + 0x3ff) & ~0x3ff;
  37. start = (start + align - 1) & ~(align - 1);
  38. return start;
  39. }
  40. /*
  41. * This is taken from the ARM code for this.
  42. */
  43. int pcibios_enable_device(struct pci_dev *dev, int mask)
  44. {
  45. struct resource *r;
  46. u16 cmd, newcmd;
  47. int idx;
  48. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  49. newcmd = cmd;
  50. for (idx = 0; idx < 6; idx++) {
  51. /* Only set up the requested stuff */
  52. if (!(mask & (1 << idx)))
  53. continue;
  54. r = dev->resource + idx;
  55. if (!r->start && r->end) {
  56. pr_err("PCI: Device %s not available because of resource collisions\n",
  57. pci_name(dev));
  58. return -EINVAL;
  59. }
  60. if (r->flags & IORESOURCE_IO)
  61. newcmd |= PCI_COMMAND_IO;
  62. if (r->flags & IORESOURCE_MEM)
  63. newcmd |= PCI_COMMAND_MEMORY;
  64. }
  65. /*
  66. * Bridges (eg, cardbus bridges) need to be fully enabled
  67. */
  68. if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
  69. newcmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
  70. if (newcmd != cmd) {
  71. pr_info("PCI: enabling device %s (0x%04x -> 0x%04x)\n",
  72. pci_name(dev), cmd, newcmd);
  73. pci_write_config_word(dev, PCI_COMMAND, newcmd);
  74. }
  75. return 0;
  76. }
  77. void pcibios_fixup_bus(struct pci_bus *bus)
  78. {
  79. struct pci_dev *dev;
  80. list_for_each_entry(dev, &bus->devices, bus_list) {
  81. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 8);
  82. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 32);
  83. }
  84. }
  85. char *pcibios_setup(char *str)
  86. {
  87. return str;
  88. }