drivers/intel/gma: Move extended VBT just below opregion

Currently the flow for opregion init is as below:
1. Allocate memory for opregion first (cbmem_add(opregion))
2. Check if VBT size > 6 KiB (this requires extended VBT support)
3. In case of extended VBT requirement, we allocate another chunk
   of memory which is equal to size of VBT (cbmem_add(extended_vbt))
4. Pass physical address pointer to OS via RVDA

We can optimize the above flow to allocate single chunk of memory by
checking VBT size in earlier step. The new optimized flow for opregion
init is as below:
1. Check if VBT size > 6 KiB (this requires extended VBT support)
2. In case of extended VBT requirement, total memory to be allocated
   is calculated as sizeof(opregion) + sizeof (extended_vbt)
   In case where VBT size is < 6 KiB, total memory requirement would
   be equal to sizeof(opregion)
3. Based on above calculation, allocate single chunk of memory based on
   total size.

This will also be helpful for the case of virtualization where guest
users don't have access to physical address and when it needs relative
address of VBT compared to absolute address.

In case of opregion 2.1 spec, we need to pass relative address of
VBT from opregion base in RVDA. This optimization will help in meeting
this requirement since relative address of extended VBT is easy to get.
This change will ensure that it meets opregion specification
requirement and will be compatible with future versions as well.

BUG=b:190019970
BRANCH=None
TEST=check the address of extended VBT region and address is coming
correctly.

Change-Id: Ic0e255df63145409096b0b9312c6c51c05f49931
Signed-off-by: Maulik V Vaghela <maulik.v.vaghela@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/55341
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
This commit is contained in:
Maulik V Vaghela 2021-06-09 11:36:20 +05:30 committed by Tim Wawrzynczak
parent 5bb7dc4e05
commit a6b60ebedb
1 changed files with 24 additions and 15 deletions

View File

@ -265,13 +265,28 @@ static inline bool is_ext_vbt_required(igd_opregion_t *opregion, optionrom_vbt_t
return (vbt->hdr_vbt_size > sizeof(opregion->vbt.gvd1)); return (vbt->hdr_vbt_size > sizeof(opregion->vbt.gvd1));
} }
/*
* Copy extended VBT at the end of opregion and fill rvda and rvds
* values correctly for the opregion.
*/
static void opregion_add_ext_vbt(igd_opregion_t *opregion, uint8_t *ext_vbt,
optionrom_vbt_t *vbt)
{
/* Copy VBT into extended VBT region (at offset 8 KiB) */
memcpy(ext_vbt, vbt, vbt->hdr_vbt_size);
/* Fill RVDA value with address of physical pointer */
opregion->mailbox3.rvda = (uintptr_t)ext_vbt;
opregion->mailbox3.rvds = vbt->hdr_vbt_size;
}
/* Initialize IGD OpRegion, called from ACPI code and OS drivers */ /* Initialize IGD OpRegion, called from ACPI code and OS drivers */
enum cb_err intel_gma_init_igd_opregion(void) enum cb_err intel_gma_init_igd_opregion(void)
{ {
igd_opregion_t *opregion; igd_opregion_t *opregion;
struct region_device rdev; struct region_device rdev;
optionrom_vbt_t *vbt = NULL; optionrom_vbt_t *vbt = NULL;
optionrom_vbt_t *ext_vbt = NULL; size_t opregion_size = sizeof(igd_opregion_t);
if (acpi_is_wakeup_s3()) if (acpi_is_wakeup_s3())
return intel_gma_restore_opregion(); return intel_gma_restore_opregion();
@ -291,13 +306,16 @@ enum cb_err intel_gma_init_igd_opregion(void)
return CB_ERR; return CB_ERR;
} }
opregion = cbmem_add(CBMEM_ID_IGD_OPREGION, sizeof(*opregion)); if (is_ext_vbt_required(opregion, vbt))
opregion_size += vbt->hdr_vbt_size;
opregion = cbmem_add(CBMEM_ID_IGD_OPREGION, opregion_size);
if (!opregion) { if (!opregion) {
printk(BIOS_ERR, "GMA: Failed to add IGD OpRegion to CBMEM.\n"); printk(BIOS_ERR, "GMA: Failed to add IGD OpRegion to CBMEM.\n");
return CB_ERR; return CB_ERR;
} }
memset(opregion, 0, sizeof(igd_opregion_t)); memset(opregion, 0, opregion_size);
memcpy(&opregion->header.signature, IGD_OPREGION_SIGNATURE, memcpy(&opregion->header.signature, IGD_OPREGION_SIGNATURE,
sizeof(opregion->header.signature)); sizeof(opregion->header.signature));
@ -305,18 +323,9 @@ enum cb_err intel_gma_init_igd_opregion(void)
ARRAY_SIZE(vbt->coreblock_biosbuild)); ARRAY_SIZE(vbt->coreblock_biosbuild));
/* Extended VBT support */ /* Extended VBT support */
if (is_ext_vbt_required(opregion, vbt)) { if (is_ext_vbt_required(opregion, vbt)) {
ext_vbt = cbmem_add(CBMEM_ID_EXT_VBT, vbt->hdr_vbt_size); /* Place extended VBT just after opregion */
uint8_t *ext_vbt = (uint8_t *)opregion + sizeof(*opregion);
if (ext_vbt == NULL) { opregion_add_ext_vbt(opregion, ext_vbt, vbt);
printk(BIOS_ERR,
"GMA: Unable to add Ext VBT to cbmem!\n");
rdev_munmap(&rdev, vbt);
return CB_ERR;
}
memcpy(ext_vbt, vbt, vbt->hdr_vbt_size);
opregion->mailbox3.rvda = (uintptr_t)ext_vbt;
opregion->mailbox3.rvds = vbt->hdr_vbt_size;
} else { } else {
/* Raw VBT size which can fit in gvd1 */ /* Raw VBT size which can fit in gvd1 */
memcpy(opregion->vbt.gvd1, vbt, vbt->hdr_vbt_size); memcpy(opregion->vbt.gvd1, vbt, vbt->hdr_vbt_size);