Angel Pons | c74dae9 | 2020-04-02 23:48:16 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 2 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 3 | #include <console/console.h> |
Marshall Dawson | 6f978cf | 2017-04-19 18:31:07 -0600 | [diff] [blame] | 4 | #include <commonlib/endian.h> |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <device/pci_ops.h> |
Stefan Reinauer | d98cf5b | 2008-08-01 11:25:41 +0000 | [diff] [blame] | 9 | #include <string.h> |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 10 | #include <cbfs.h> |
Patrick Rudolph | 00c0cd2 | 2017-06-06 19:30:55 +0200 | [diff] [blame] | 11 | #include <cbmem.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 12 | #include <acpi/acpigen.h> |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 13 | |
Kyösti Mälkki | 1bdd321 | 2014-12-26 13:29:09 +0200 | [diff] [blame] | 14 | /* Rmodules don't like weak symbols. */ |
Martin Roth | dafcc7a | 2020-02-05 16:46:30 -0700 | [diff] [blame] | 15 | void __weak map_oprom_vendev_rev(u32 *vendev, u8 *rev) { return; } |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 16 | u32 __weak map_oprom_vendev(u32 vendev) { return vendev; } |
Kyösti Mälkki | 1bdd321 | 2014-12-26 13:29:09 +0200 | [diff] [blame] | 17 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 18 | struct rom_header *pci_rom_probe(const struct device *dev) |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 19 | { |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 20 | struct rom_header *rom_header = NULL; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 21 | struct pci_data *rom_data; |
Martin Roth | dafcc7a | 2020-02-05 16:46:30 -0700 | [diff] [blame] | 22 | u8 rev = pci_read_config8(dev, PCI_REVISION_ID); |
| 23 | u8 mapped_rev = rev; |
| 24 | u32 vendev = (dev->vendor << 16) | dev->device; |
| 25 | u32 mapped_vendev = vendev; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 26 | |
Martin Roth | dafcc7a | 2020-02-05 16:46:30 -0700 | [diff] [blame] | 27 | /* If the ROM is in flash, then don't check the PCI device for it. */ |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 28 | if (CONFIG(CHECK_REV_IN_OPROM_NAME)) { |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 29 | rom_header = cbfs_boot_map_optionrom_revision(dev->vendor, dev->device, rev); |
Martin Roth | dafcc7a | 2020-02-05 16:46:30 -0700 | [diff] [blame] | 30 | map_oprom_vendev_rev(&mapped_vendev, &mapped_rev); |
| 31 | } else { |
| 32 | rom_header = cbfs_boot_map_optionrom(dev->vendor, dev->device); |
| 33 | mapped_vendev = map_oprom_vendev(vendev); |
Martin Roth | a616a4b | 2020-01-21 09:28:40 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Stefan Reinauer | c0a6c6b | 2012-01-23 14:17:52 -0800 | [diff] [blame] | 36 | if (!rom_header) { |
Martin Roth | dafcc7a | 2020-02-05 16:46:30 -0700 | [diff] [blame] | 37 | if (CONFIG(CHECK_REV_IN_OPROM_NAME) && |
| 38 | (vendev != mapped_vendev || rev != mapped_rev)) { |
| 39 | rom_header = cbfs_boot_map_optionrom_revision( |
| 40 | mapped_vendev >> 16, |
| 41 | mapped_vendev & 0xffff, mapped_rev); |
| 42 | } else if (vendev != mapped_vendev) { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 43 | rom_header = cbfs_boot_map_optionrom( |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 44 | mapped_vendev >> 16, |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 45 | mapped_vendev & 0xffff); |
Stefan Reinauer | c0a6c6b | 2012-01-23 14:17:52 -0800 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 49 | if (rom_header) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 50 | printk(BIOS_DEBUG, "In CBFS, ROM address for %s = %p\n", |
| 51 | dev_path(dev), rom_header); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 52 | } else if (!CONFIG(ON_DEVICE_ROM_LOAD)) { |
Elyes HAOUAS | c32ccb7 | 2019-06-14 23:27:26 +0200 | [diff] [blame] | 53 | printk(BIOS_DEBUG, "PCI Option ROM loading disabled for %s\n", |
| 54 | dev_path(dev)); |
| 55 | return NULL; |
Ronald G. Minnich | a88db7b | 2009-06-09 14:44:37 +0000 | [diff] [blame] | 56 | } else { |
Stefan Reinauer | 83fa169 | 2015-06-18 22:01:07 -0700 | [diff] [blame] | 57 | uintptr_t rom_address; |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 58 | |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 59 | rom_address = pci_read_config32(dev, PCI_ROM_ADDRESS); |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 60 | |
| 61 | if (rom_address == 0x00000000 || rom_address == 0xffffffff) { |
Angel Pons | d615230 | 2020-03-01 14:46:38 +0100 | [diff] [blame] | 62 | #if CONFIG(CPU_QEMU_X86) |
Myles Watson | ae3e998 | 2009-11-17 15:20:22 +0000 | [diff] [blame] | 63 | if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA) |
| 64 | rom_address = 0xc0000; |
| 65 | else |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 66 | #endif |
Myles Watson | ae3e998 | 2009-11-17 15:20:22 +0000 | [diff] [blame] | 67 | return NULL; |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 68 | } else { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 69 | /* Enable expansion ROM address decoding. */ |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 70 | pci_write_config32(dev, PCI_ROM_ADDRESS, |
| 71 | rom_address|PCI_ROM_ADDRESS_ENABLE); |
| 72 | } |
| 73 | |
Kyösti Mälkki | 8c9be43 | 2019-06-29 22:34:07 +0300 | [diff] [blame] | 74 | rom_address &= PCI_ROM_ADDRESS_MASK; |
| 75 | |
Stefan Reinauer | afaa257 | 2011-10-06 16:47:51 -0700 | [diff] [blame] | 76 | printk(BIOS_DEBUG, "Option ROM address for %s = %lx\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 77 | dev_path(dev), (unsigned long)rom_address); |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 78 | rom_header = (struct rom_header *)rom_address; |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 79 | } |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 80 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 81 | printk(BIOS_SPEW, "PCI expansion ROM, signature 0x%04x, " |
| 82 | "INIT size 0x%04x, data ptr 0x%04x\n", |
| 83 | le32_to_cpu(rom_header->signature), |
| 84 | rom_header->size * 512, le32_to_cpu(rom_header->data)); |
| 85 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 86 | if (le32_to_cpu(rom_header->signature) != PCI_ROM_HDR) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 87 | printk(BIOS_ERR, "Incorrect expansion ROM header " |
| 88 | "signature %04x\n", le32_to_cpu(rom_header->signature)); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 89 | return NULL; |
| 90 | } |
| 91 | |
Myles Watson | d27c08c | 2009-11-06 23:42:26 +0000 | [diff] [blame] | 92 | rom_data = (((void *)rom_header) + le32_to_cpu(rom_header->data)); |
| 93 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 94 | printk(BIOS_SPEW, "PCI ROM image, vendor ID %04x, device ID %04x,\n", |
| 95 | rom_data->vendor, rom_data->device); |
Stefan Reinauer | c0a6c6b | 2012-01-23 14:17:52 -0800 | [diff] [blame] | 96 | /* If the device id is mapped, a mismatch is expected */ |
| 97 | if ((dev->vendor != rom_data->vendor |
| 98 | || dev->device != rom_data->device) |
| 99 | && (vendev == mapped_vendev)) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 100 | printk(BIOS_ERR, "ID mismatch: vendor ID %04x, " |
Martin Roth | b6e2afb | 2020-01-21 08:57:00 -0700 | [diff] [blame] | 101 | "device ID %04x\n", dev->vendor, dev->device); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 102 | return NULL; |
| 103 | } |
| 104 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 105 | printk(BIOS_SPEW, "PCI ROM image, Class Code %04x%02x, " |
| 106 | "Code Type %02x\n", rom_data->class_hi, rom_data->class_lo, |
| 107 | rom_data->type); |
| 108 | |
Yinghai Lu | 54ab311 | 2005-01-18 03:10:46 +0000 | [diff] [blame] | 109 | if (dev->class != ((rom_data->class_hi << 8) | rom_data->class_lo)) { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 110 | printk(BIOS_DEBUG, "Class Code mismatch ROM %08x, dev %08x\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 111 | (rom_data->class_hi << 8) | rom_data->class_lo, |
| 112 | dev->class); |
| 113 | // return NULL; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | return rom_header; |
| 117 | } |
| 118 | |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 119 | static void *pci_ram_image_start = (void *)PCI_RAM_IMAGE_START; |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 120 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 121 | struct rom_header *pci_rom_load(struct device *dev, |
| 122 | struct rom_header *rom_header) |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 123 | { |
| 124 | struct pci_data * rom_data; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 125 | unsigned int rom_size; |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 126 | unsigned int image_size=0; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 127 | |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 128 | do { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 129 | /* Get next image. */ |
| 130 | rom_header = (struct rom_header *)((void *) rom_header |
| 131 | + image_size); |
| 132 | |
| 133 | rom_data = (struct pci_data *)((void *) rom_header |
| 134 | + le32_to_cpu(rom_header->data)); |
| 135 | |
| 136 | image_size = le32_to_cpu(rom_data->ilen) * 512; |
| 137 | } while ((rom_data->type != 0) && (rom_data->indicator != 0)); // make sure we got x86 version |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 138 | |
Stefan Reinauer | 4d59eaa | 2009-04-22 16:32:18 +0000 | [diff] [blame] | 139 | if (rom_data->type != 0) |
| 140 | return NULL; |
arch import user (historical) | 2305364 | 2005-07-06 16:49:59 +0000 | [diff] [blame] | 141 | |
| 142 | rom_size = rom_header->size * 512; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 143 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 144 | /* |
| 145 | * We check to see if the device thinks it is a VGA device not |
| 146 | * whether the ROM image is for a VGA device because some |
| 147 | * devices have a mismatch between the hardware and the ROM. |
| 148 | */ |
Elyes HAOUAS | 0f8b8d9 | 2019-01-03 10:23:28 +0100 | [diff] [blame] | 149 | if ((dev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 150 | #if !CONFIG(MULTIPLE_VGA_ADAPTERS) |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 151 | extern struct device *vga_pri; /* Primary VGA device (device.c). */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 152 | if (dev != vga_pri) return NULL; /* Only one VGA supported. */ |
Roman Kononov | d6d7a11 | 2007-04-09 22:50:12 +0000 | [diff] [blame] | 153 | #endif |
Ronald G. Minnich | a88db7b | 2009-06-09 14:44:37 +0000 | [diff] [blame] | 154 | if ((void *)PCI_VGA_RAM_IMAGE_START != rom_header) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 155 | printk(BIOS_DEBUG, "Copying VGA ROM Image from %p to " |
| 156 | "0x%x, 0x%x bytes\n", rom_header, |
| 157 | PCI_VGA_RAM_IMAGE_START, rom_size); |
| 158 | memcpy((void *)PCI_VGA_RAM_IMAGE_START, rom_header, |
| 159 | rom_size); |
Ronald G. Minnich | a88db7b | 2009-06-09 14:44:37 +0000 | [diff] [blame] | 160 | } |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 161 | return (struct rom_header *) (PCI_VGA_RAM_IMAGE_START); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 162 | } |
Stefan Reinauer | 4d59eaa | 2009-04-22 16:32:18 +0000 | [diff] [blame] | 163 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 164 | printk(BIOS_DEBUG, "Copying non-VGA ROM image from %p to %p, 0x%x " |
| 165 | "bytes\n", rom_header, pci_ram_image_start, rom_size); |
Stefan Reinauer | 4d59eaa | 2009-04-22 16:32:18 +0000 | [diff] [blame] | 166 | |
| 167 | memcpy(pci_ram_image_start, rom_header, rom_size); |
| 168 | pci_ram_image_start += rom_size; |
| 169 | return (struct rom_header *) (pci_ram_image_start-rom_size); |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 170 | } |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 171 | |
| 172 | /* ACPI */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 173 | #if CONFIG(HAVE_ACPI_TABLES) |
Marshall Dawson | 6f978cf | 2017-04-19 18:31:07 -0600 | [diff] [blame] | 174 | |
| 175 | /* VBIOS may be modified after oprom init so use the copy if present. */ |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 176 | static struct rom_header *check_initialized(const struct device *dev) |
Marshall Dawson | 6f978cf | 2017-04-19 18:31:07 -0600 | [diff] [blame] | 177 | { |
| 178 | struct rom_header *run_rom; |
| 179 | struct pci_data *rom_data; |
| 180 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 181 | if (!CONFIG(VGA_ROM_RUN)) |
Marshall Dawson | 6f978cf | 2017-04-19 18:31:07 -0600 | [diff] [blame] | 182 | return NULL; |
| 183 | |
| 184 | run_rom = (struct rom_header *)(uintptr_t)PCI_VGA_RAM_IMAGE_START; |
| 185 | if (read_le16(&run_rom->signature) != PCI_ROM_HDR) |
| 186 | return NULL; |
| 187 | |
| 188 | rom_data = (struct pci_data *)((u8 *)run_rom |
Jacob Garber | 7cfe68d | 2019-07-16 13:14:09 -0600 | [diff] [blame] | 189 | + read_le16(&run_rom->data)); |
Marshall Dawson | 6f978cf | 2017-04-19 18:31:07 -0600 | [diff] [blame] | 190 | |
| 191 | if (read_le32(&rom_data->signature) == PCI_DATA_HDR |
| 192 | && read_le16(&rom_data->device) == dev->device |
| 193 | && read_le16(&rom_data->vendor) == dev->vendor) |
| 194 | return run_rom; |
| 195 | else |
| 196 | return NULL; |
| 197 | } |
| 198 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 199 | static unsigned long |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 200 | pci_rom_acpi_fill_vfct(const struct device *device, acpi_vfct_t *vfct_struct, |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 201 | unsigned long current) |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 202 | { |
Himanshu Sahdev | afd0505 | 2019-10-21 11:23:20 +0530 | [diff] [blame] | 203 | acpi_vfct_image_hdr_t *header = &vfct_struct->image_hdr; |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 204 | struct rom_header *rom; |
| 205 | |
Marshall Dawson | 6f978cf | 2017-04-19 18:31:07 -0600 | [diff] [blame] | 206 | rom = check_initialized(device); |
| 207 | if (!rom) |
| 208 | rom = pci_rom_probe(device); |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 209 | if (!rom) { |
| 210 | printk(BIOS_ERR, "pci_rom_acpi_fill_vfct failed\n"); |
| 211 | return current; |
| 212 | } |
| 213 | |
Marshall Dawson | 6f978cf | 2017-04-19 18:31:07 -0600 | [diff] [blame] | 214 | printk(BIOS_DEBUG, " Copying %sVBIOS image from %p\n", |
| 215 | rom == (struct rom_header *) |
| 216 | (uintptr_t)PCI_VGA_RAM_IMAGE_START ? |
| 217 | "initialized " : "", |
| 218 | rom); |
| 219 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 220 | header->DeviceID = device->device; |
| 221 | header->VendorID = device->vendor; |
| 222 | header->PCIBus = device->bus->secondary; |
| 223 | header->PCIFunction = PCI_FUNC(device->path.pci.devfn); |
| 224 | header->PCIDevice = PCI_SLOT(device->path.pci.devfn); |
| 225 | header->ImageLength = rom->size * 512; |
| 226 | memcpy((void *)&header->VbiosContent, rom, header->ImageLength); |
| 227 | |
Kyösti Mälkki | fb49379 | 2019-06-30 06:29:52 +0300 | [diff] [blame] | 228 | vfct_struct->VBIOSImageOffset = (size_t)header - (size_t)vfct_struct; |
| 229 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 230 | current += header->ImageLength; |
| 231 | return current; |
| 232 | } |
| 233 | |
| 234 | unsigned long |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 235 | pci_rom_write_acpi_tables(const struct device *device, unsigned long current, |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 236 | struct acpi_rsdp *rsdp) |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 237 | { |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 238 | /* Only handle VGA devices */ |
| 239 | if ((device->class >> 8) != PCI_CLASS_DISPLAY_VGA) |
| 240 | return current; |
| 241 | |
| 242 | /* Only handle enabled devices */ |
| 243 | if (!device->enabled) |
| 244 | return current; |
| 245 | |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 246 | /* AMD/ATI uses VFCT */ |
| 247 | if (device->vendor == PCI_VENDOR_ID_ATI) { |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 248 | acpi_vfct_t *vfct; |
Kyösti Mälkki | fb49379 | 2019-06-30 06:29:52 +0300 | [diff] [blame] | 249 | |
Felix Held | d5a11ed | 2019-06-20 14:35:44 +0200 | [diff] [blame] | 250 | current = ALIGN_UP(current, 8); |
Himanshu Sahdev | 7f1da07 | 2019-10-21 15:27:19 +0530 | [diff] [blame] | 251 | vfct = (acpi_vfct_t *)current; |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 252 | acpi_create_vfct(device, vfct, pci_rom_acpi_fill_vfct); |
Kyösti Mälkki | fb49379 | 2019-06-30 06:29:52 +0300 | [diff] [blame] | 253 | if (vfct->header.length) { |
| 254 | printk(BIOS_DEBUG, "ACPI: * VFCT at %lx\n", current); |
| 255 | current += vfct->header.length; |
| 256 | acpi_add_table(rsdp, vfct); |
| 257 | } |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | return current; |
| 261 | } |
Patrick Rudolph | 00c0cd2 | 2017-06-06 19:30:55 +0200 | [diff] [blame] | 262 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 263 | void pci_rom_ssdt(const struct device *device) |
Patrick Rudolph | 00c0cd2 | 2017-06-06 19:30:55 +0200 | [diff] [blame] | 264 | { |
| 265 | static size_t ngfx; |
| 266 | |
| 267 | /* Only handle VGA devices */ |
| 268 | if ((device->class >> 8) != PCI_CLASS_DISPLAY_VGA) |
| 269 | return; |
| 270 | |
| 271 | /* Only handle enabled devices */ |
| 272 | if (!device->enabled) |
| 273 | return; |
| 274 | |
| 275 | /* Probe for option rom */ |
| 276 | const struct rom_header *rom = pci_rom_probe(device); |
| 277 | if (!rom || !rom->size) { |
| 278 | printk(BIOS_WARNING, "%s: Missing PCI Option ROM\n", |
| 279 | dev_path(device)); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | const char *scope = acpi_device_path(device); |
| 284 | if (!scope) { |
| 285 | printk(BIOS_ERR, "%s: Missing ACPI scope\n", dev_path(device)); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | /* Supports up to four devices. */ |
| 290 | if ((CBMEM_ID_ROM0 + ngfx) > CBMEM_ID_ROM3) { |
| 291 | printk(BIOS_ERR, "%s: Out of CBMEM IDs.\n", dev_path(device)); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | /* Prepare memory */ |
| 296 | const size_t cbrom_length = rom->size * 512; |
| 297 | if (!cbrom_length) { |
| 298 | printk(BIOS_ERR, "%s: ROM has zero length!\n", |
| 299 | dev_path(device)); |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | void *cbrom = cbmem_add(CBMEM_ID_ROM0 + ngfx, cbrom_length); |
| 304 | if (!cbrom) { |
| 305 | printk(BIOS_ERR, "%s: Failed to allocate CBMEM.\n", |
| 306 | dev_path(device)); |
| 307 | return; |
| 308 | } |
| 309 | /* Increment CBMEM id for next device */ |
| 310 | ngfx++; |
| 311 | |
| 312 | memcpy(cbrom, rom, cbrom_length); |
| 313 | |
| 314 | /* write _ROM method */ |
| 315 | acpigen_write_scope(scope); |
| 316 | acpigen_write_rom(cbrom, cbrom_length); |
| 317 | acpigen_pop_len(); /* pop scope */ |
| 318 | } |
Patrick Rudolph | a5c2ac6 | 2016-03-31 20:04:23 +0200 | [diff] [blame] | 319 | #endif |