fixup.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Exceptions for specific devices. Usually work-arounds for fatal design flaws.
  3. * Derived from fixup.c of i386 tree.
  4. */
  5. #include <linux/pci.h>
  6. #include <linux/init.h>
  7. #include <linux/vgaarb.h>
  8. #include <linux/screen_info.h>
  9. #include <asm/machvec.h>
  10. /*
  11. * Fixup to mark boot BIOS video selected by BIOS before it changes
  12. *
  13. * From information provided by "Jon Smirl" <jonsmirl@gmail.com>
  14. *
  15. * The standard boot ROM sequence for an x86 machine uses the BIOS
  16. * to select an initial video card for boot display. This boot video
  17. * card will have it's BIOS copied to C0000 in system RAM.
  18. * IORESOURCE_ROM_SHADOW is used to associate the boot video
  19. * card with this copy. On laptops this copy has to be used since
  20. * the main ROM may be compressed or combined with another image.
  21. * See pci_map_rom() for use of this flag. Before marking the device
  22. * with IORESOURCE_ROM_SHADOW check if a vga_default_device is already set
  23. * by either arch cde or vga-arbitration, if so only apply the fixup to this
  24. * already determined primary video card.
  25. */
  26. static void pci_fixup_video(struct pci_dev *pdev)
  27. {
  28. struct pci_dev *bridge;
  29. struct pci_bus *bus;
  30. u16 config;
  31. if ((strcmp(ia64_platform_name, "dig") != 0)
  32. && (strcmp(ia64_platform_name, "hpzx1") != 0))
  33. return;
  34. /* Maybe, this machine supports legacy memory map. */
  35. if (!vga_default_device()) {
  36. resource_size_t start, end;
  37. int i;
  38. /* Does firmware framebuffer belong to us? */
  39. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  40. if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM))
  41. continue;
  42. start = pci_resource_start(pdev, i);
  43. end = pci_resource_end(pdev, i);
  44. if (!start || !end)
  45. continue;
  46. if (screen_info.lfb_base >= start &&
  47. (screen_info.lfb_base + screen_info.lfb_size) < end)
  48. vga_set_default_device(pdev);
  49. }
  50. }
  51. /* Is VGA routed to us? */
  52. bus = pdev->bus;
  53. while (bus) {
  54. bridge = bus->self;
  55. /*
  56. * From information provided by
  57. * "David Miller" <davem@davemloft.net>
  58. * The bridge control register is valid for PCI header
  59. * type BRIDGE, or CARDBUS. Host to PCI controllers use
  60. * PCI header type NORMAL.
  61. */
  62. if (bridge && (pci_is_bridge(bridge))) {
  63. pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
  64. &config);
  65. if (!(config & PCI_BRIDGE_CTL_VGA))
  66. return;
  67. }
  68. bus = bus->parent;
  69. }
  70. if (!vga_default_device() || pdev == vga_default_device()) {
  71. pci_read_config_word(pdev, PCI_COMMAND, &config);
  72. if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) {
  73. pdev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_SHADOW;
  74. dev_printk(KERN_DEBUG, &pdev->dev, "Boot video device\n");
  75. vga_set_default_device(pdev);
  76. }
  77. }
  78. }
  79. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
  80. PCI_CLASS_DISPLAY_VGA, 8, pci_fixup_video);