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