blob: e1fa45b2148c12045f8f2a950ba39e2193b958f9 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +09002/*
3 * Exceptions for specific devices. Usually work-arounds for fatal design flaws.
4 * Derived from fixup.c of i386 tree.
5 */
6
7#include <linux/pci.h>
8#include <linux/init.h>
Sander Eikelenboom058a2e12014-02-14 11:55:13 -07009#include <linux/vgaarb.h>
Bruno Prémont20cde692014-06-25 00:55:01 +020010#include <linux/screen_info.h>
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090011
12#include <asm/machvec.h>
13
14/*
15 * Fixup to mark boot BIOS video selected by BIOS before it changes
16 *
17 * From information provided by "Jon Smirl" <jonsmirl@gmail.com>
18 *
19 * The standard boot ROM sequence for an x86 machine uses the BIOS
20 * to select an initial video card for boot display. This boot video
Bjorn Helgaas0c0e0732016-03-01 11:38:46 -060021 * card will have its BIOS copied to 0xC0000 in system RAM.
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090022 * IORESOURCE_ROM_SHADOW is used to associate the boot video
23 * card with this copy. On laptops this copy has to be used since
24 * the main ROM may be compressed or combined with another image.
Sander Eikelenboom058a2e12014-02-14 11:55:13 -070025 * See pci_map_rom() for use of this flag. Before marking the device
26 * with IORESOURCE_ROM_SHADOW check if a vga_default_device is already set
Bjorn Helgaas0c0e0732016-03-01 11:38:46 -060027 * by either arch code or vga-arbitration; if so only apply the fixup to this
28 * already-determined primary video card.
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090029 */
30
Greg Kroah-Hartman5b5e76e2012-12-21 14:05:13 -080031static void pci_fixup_video(struct pci_dev *pdev)
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090032{
33 struct pci_dev *bridge;
34 struct pci_bus *bus;
35 u16 config;
Bjorn Helgaas0c0e0732016-03-01 11:38:46 -060036 struct resource *res;
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090037
Fengguang Wuf9445a32012-07-25 15:15:13 +080038 if ((strcmp(ia64_platform_name, "dig") != 0)
39 && (strcmp(ia64_platform_name, "hpzx1") != 0))
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090040 return;
41 /* Maybe, this machine supports legacy memory map. */
42
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090043 /* Is VGA routed to us? */
44 bus = pdev->bus;
45 while (bus) {
46 bridge = bus->self;
47
48 /*
49 * From information provided by
50 * "David Miller" <davem@davemloft.net>
51 * The bridge control register is valid for PCI header
52 * type BRIDGE, or CARDBUS. Host to PCI controllers use
53 * PCI header type NORMAL.
54 */
Yijing Wang11a3bd02014-05-04 12:23:40 +080055 if (bridge && (pci_is_bridge(bridge))) {
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090056 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
57 &config);
58 if (!(config & PCI_BRIDGE_CTL_VGA))
59 return;
60 }
61 bus = bus->parent;
62 }
Sander Eikelenboom058a2e12014-02-14 11:55:13 -070063 if (!vga_default_device() || pdev == vga_default_device()) {
64 pci_read_config_word(pdev, PCI_COMMAND, &config);
65 if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) {
Bjorn Helgaas0c0e0732016-03-01 11:38:46 -060066 res = &pdev->resource[PCI_ROM_RESOURCE];
67
68 pci_disable_rom(pdev);
69 if (res->parent)
70 release_resource(res);
71
72 res->start = 0xC0000;
73 res->end = res->start + 0x20000 - 1;
74 res->flags = IORESOURCE_MEM | IORESOURCE_ROM_SHADOW |
75 IORESOURCE_PCI_FIXED;
76 dev_info(&pdev->dev, "Video device with shadowed ROM at %pR\n",
77 res);
Sander Eikelenboom058a2e12014-02-14 11:55:13 -070078 }
Eiichiro Oiwa6b5c76b2006-10-23 15:14:07 +090079 }
80}
Sander Eikelenboom058a2e12014-02-14 11:55:13 -070081DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
82 PCI_CLASS_DISPLAY_VGA, 8, pci_fixup_video);