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