Kyösti Mälkki has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/31318
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
soc/amd/common: Move PI refcode loader
The moved functions are only about locating and loading the refcode blobs. Separate them from the actual calls into the blob. Eventually previous binaryPI blobs should be unified share same loader code.
Change-Id: I68885e7f855b195c178e746c8f3f0f49166d0def Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- M src/soc/amd/common/block/pi/Makefile.inc M src/soc/amd/common/block/pi/agesawrapper.c A src/soc/amd/common/block/pi/refcode_loader.c 3 files changed, 160 insertions(+), 139 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/18/31318/1
diff --git a/src/soc/amd/common/block/pi/Makefile.inc b/src/soc/amd/common/block/pi/Makefile.inc index ba08123..5afbb3e 100644 --- a/src/soc/amd/common/block/pi/Makefile.inc +++ b/src/soc/amd/common/block/pi/Makefile.inc @@ -4,6 +4,7 @@ romstage-y += def_callouts.c romstage-y += heapmanager.c romstage-y += image.c +romstage-y += refcode_loader.c
ramstage-y += agesawrapper.c ramstage-y += amd_late_init.c @@ -11,5 +12,6 @@ ramstage-y += def_callouts.c ramstage-y += heapmanager.c ramstage-y += image.c +ramstage-y += refcode_loader.c
endif diff --git a/src/soc/amd/common/block/pi/agesawrapper.c b/src/soc/amd/common/block/pi/agesawrapper.c index a57ac4f..07461b8 100644 --- a/src/soc/amd/common/block/pi/agesawrapper.c +++ b/src/soc/amd/common/block/pi/agesawrapper.c @@ -14,14 +14,9 @@ * GNU General Public License for more details. */
-#include <arch/early_variables.h> #include <arch/acpi.h> -#include <cpu/x86/mtrr.h> -#include <cbfs.h> #include <cbmem.h> #include <delay.h> -#include <rmodule.h> -#include <stage_cache.h> #include <string.h> #include <timestamp.h> #include <amdblocks/s3_resume.h> @@ -480,137 +475,3 @@
return Status; } - -static int agesa_locate_file(const char *name, struct region_device *rdev, - uint32_t type) -{ - struct cbfsf fh; - - if (cbfs_boot_locate(&fh, name, &type)) - return -1; - - cbfs_file_data(rdev, &fh); - return 0; -} - -static int agesa_locate_raw_file(const char *name, struct region_device *rdev) -{ - return agesa_locate_file(name, rdev, CBFS_TYPE_RAW); -} - -static int agesa_locate_stage_file_early(const char *name, - struct region_device *rdev) -{ - const size_t metadata_sz = sizeof(struct cbfs_stage); - - if (agesa_locate_file(name, rdev, CBFS_TYPE_STAGE)) - return -1; - - /* Peel off the cbfs stage metadata. */ - return rdev_chain(rdev, rdev, metadata_sz, - region_device_sz(rdev) - metadata_sz); -} - -static int agesa_locate_stage_file_ramstage(const char *name, - struct region_device *rdev) -{ - struct prog prog = PROG_INIT(PROG_REFCODE, name); - struct rmod_stage_load rmod_agesa = { - .cbmem_id = CBMEM_ID_REFCODE, - .prog = &prog, - }; - - if (acpi_is_wakeup_s3() && !IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { - printk(BIOS_INFO, "AGESA: Loading stage from cache\n"); - // There is no way to tell if this succeeded. - stage_cache_load_stage(STAGE_REFCODE, &prog); - } else { - if (prog_locate(&prog)) - return -1; - - if (rmodule_stage_load(&rmod_agesa) < 0) - return -1; - - if (!IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { - printk(BIOS_INFO, "AGESA: Saving stage to cache\n"); - stage_cache_add(STAGE_REFCODE, &prog); - } - } - - return rdev_chain(rdev, prog_rdev(&prog), 0, - region_device_sz(prog_rdev(&prog))); -} - -static int agesa_locate_stage_file(const char *name, struct region_device *rdev) -{ - if (!ENV_RAMSTAGE || !IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) - return agesa_locate_stage_file_early(name, rdev); - return agesa_locate_stage_file_ramstage(name, rdev); -} - -static const char *get_agesa_cbfs_name(void) -{ - if (!IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) - return CONFIG_AGESA_CBFS_NAME; - if (!ENV_RAMSTAGE) - return CONFIG_AGESA_PRE_MEMORY_CBFS_NAME; - return CONFIG_AGESA_POST_MEMORY_CBFS_NAME; -} - -const void *agesawrapper_locate_module(const char name[8]) -{ - const void *agesa; - const AMD_IMAGE_HEADER *image; - struct region_device rdev; - size_t file_size; - const char *fname; - int ret; - - fname = get_agesa_cbfs_name(); - - if (IS_ENABLED(CONFIG_AGESA_BINARY_PI_AS_STAGE)) - ret = agesa_locate_stage_file(fname, &rdev); - else - ret = agesa_locate_raw_file(fname, &rdev); - - if (ret) - return NULL; - - file_size = region_device_sz(&rdev); - - /* Assume boot device is memory mapped so the mapping can leak. */ - assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED)); - - agesa = rdev_mmap_full(&rdev); - - if (!agesa) - return NULL; - - image = amd_find_image(agesa, agesa + file_size, 4096, name); - - if (!image) - return NULL; - - return (AMD_MODULE_HEADER *)image->ModuleInfoOffset; -} - -static MODULE_ENTRY agesa_dispatcher CAR_GLOBAL; - -MODULE_ENTRY agesa_get_dispatcher(void) -{ - const AMD_MODULE_HEADER *module; - static const char id[8] = AGESA_ID; - MODULE_ENTRY val = car_get_var(agesa_dispatcher); - - if (val != NULL) - return val; - - module = agesawrapper_locate_module(id); - if (!module) - return NULL; - - val = module->ModuleDispatcher; - car_set_var(agesa_dispatcher, val); - - return val; -} diff --git a/src/soc/amd/common/block/pi/refcode_loader.c b/src/soc/amd/common/block/pi/refcode_loader.c new file mode 100644 index 0000000..864acfd --- /dev/null +++ b/src/soc/amd/common/block/pi/refcode_loader.c @@ -0,0 +1,158 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2012 - 2017 Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <arch/early_variables.h> +#include <arch/acpi.h> +#include <cbfs.h> +#include <cbmem.h> +#include <compiler.h> +#include <rules.h> +#include <rmodule.h> +#include <stage_cache.h> +#include <amdblocks/agesawrapper.h> + +static int agesa_locate_file(const char *name, struct region_device *rdev, + uint32_t type) +{ + struct cbfsf fh; + + if (cbfs_boot_locate(&fh, name, &type)) + return -1; + + cbfs_file_data(rdev, &fh); + return 0; +} + +static int agesa_locate_raw_file(const char *name, struct region_device *rdev) +{ + return agesa_locate_file(name, rdev, CBFS_TYPE_RAW); +} + +static int agesa_locate_stage_file_early(const char *name, + struct region_device *rdev) +{ + const size_t metadata_sz = sizeof(struct cbfs_stage); + + if (agesa_locate_file(name, rdev, CBFS_TYPE_STAGE)) + return -1; + + /* Peel off the cbfs stage metadata. */ + return rdev_chain(rdev, rdev, metadata_sz, + region_device_sz(rdev) - metadata_sz); +} + +static int agesa_locate_stage_file_ramstage(const char *name, + struct region_device *rdev) +{ + struct prog prog = PROG_INIT(PROG_REFCODE, name); + struct rmod_stage_load rmod_agesa = { + .cbmem_id = CBMEM_ID_REFCODE, + .prog = &prog, + }; + + if (acpi_is_wakeup_s3() && !IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { + printk(BIOS_INFO, "AGESA: Loading stage from cache\n"); + // There is no way to tell if this succeeded. + stage_cache_load_stage(STAGE_REFCODE, &prog); + } else { + if (prog_locate(&prog)) + return -1; + + if (rmodule_stage_load(&rmod_agesa) < 0) + return -1; + + if (!IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { + printk(BIOS_INFO, "AGESA: Saving stage to cache\n"); + stage_cache_add(STAGE_REFCODE, &prog); + } + } + + return rdev_chain(rdev, prog_rdev(&prog), 0, + region_device_sz(prog_rdev(&prog))); +} + +static int agesa_locate_stage_file(const char *name, struct region_device *rdev) +{ + if (!ENV_RAMSTAGE || !IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) + return agesa_locate_stage_file_early(name, rdev); + return agesa_locate_stage_file_ramstage(name, rdev); +} + +static const char *get_agesa_cbfs_name(void) +{ + if (!IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) + return CONFIG_AGESA_CBFS_NAME; + if (!ENV_RAMSTAGE) + return CONFIG_AGESA_PRE_MEMORY_CBFS_NAME; + return CONFIG_AGESA_POST_MEMORY_CBFS_NAME; +} + +const void *agesawrapper_locate_module(const char name[8]) +{ + const void *agesa; + const AMD_IMAGE_HEADER *image; + struct region_device rdev; + size_t file_size; + const char *fname; + int ret; + + fname = get_agesa_cbfs_name(); + + if (IS_ENABLED(CONFIG_AGESA_BINARY_PI_AS_STAGE)) + ret = agesa_locate_stage_file(fname, &rdev); + else + ret = agesa_locate_raw_file(fname, &rdev); + + if (ret) + return NULL; + + file_size = region_device_sz(&rdev); + + /* Assume boot device is memory mapped so the mapping can leak. */ + assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED)); + + agesa = rdev_mmap_full(&rdev); + + if (!agesa) + return NULL; + + image = amd_find_image(agesa, agesa + file_size, 4096, name); + + if (!image) + return NULL; + + return (AMD_MODULE_HEADER *)image->ModuleInfoOffset; +} + +static MODULE_ENTRY agesa_dispatcher CAR_GLOBAL; + +MODULE_ENTRY agesa_get_dispatcher(void) +{ + const AMD_MODULE_HEADER *module; + static const char id[8] = AGESA_ID; + MODULE_ENTRY val = car_get_var(agesa_dispatcher); + + if (val != NULL) + return val; + + module = agesawrapper_locate_module(id); + if (!module) + return NULL; + + val = module->ModuleDispatcher; + car_set_var(agesa_dispatcher, val); + + return val; +}
Hello build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/31318
to look at the new patch set (#2).
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
soc/amd/common: Move PI refcode loader
The moved functions are only about locating and loading the refcode blobs. Separate them from the actual calls into the blob. Eventually previous binaryPI blobs should be unified share same loader code.
Change-Id: I68885e7f855b195c178e746c8f3f0f49166d0def Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- M src/soc/amd/common/block/pi/Makefile.inc M src/soc/amd/common/block/pi/agesawrapper.c A src/soc/amd/common/block/pi/refcode_loader.c M src/soc/amd/stoneyridge/spi.c 4 files changed, 168 insertions(+), 143 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/18/31318/2
Hello build bot (Jenkins), Patrick Georgi, Martin Roth,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/31318
to look at the new patch set (#3).
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
soc/amd/common: Move PI refcode loader
The moved functions are only about locating and loading the refcode blobs. Separate them from the actual calls into the blob. Eventually previous binaryPI blobs should be unified to share same loader code.
Change-Id: I68885e7f855b195c178e746c8f3f0f49166d0def Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- M src/soc/amd/common/block/pi/Makefile.inc M src/soc/amd/common/block/pi/agesawrapper.c A src/soc/amd/common/block/pi/refcode_loader.c 3 files changed, 155 insertions(+), 136 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/18/31318/3
Kyösti Mälkki has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3:
I understand there were some iterations how binaryPI blobs are constructed. Could you go through the Kconfig variables and this file for deprecated and obsolete parts.
Also, instead of new file refcode_loader.c maybe move the code to image.c instead. At the time I originally did this change locally, image.c did not exist.
Richard Spiegel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3:
Not sure why you want to move code from a already existing file into a new file? Are you planning on doing this unification? What about future Agesa version 9 (currently being developed)? Should we force Agesa 9 to use this loaders? I would rather wait Martin's opinion.
Kyösti Mälkki has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3:
Martin, Aaron; Can you tell who is the person to do kahlee reviews? Seems like Marshall is removing himself from reviewers here?
Aaron Durbin has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3:
Patch Set 3:
Martin, Aaron; Can you tell who is the person to do kahlee reviews? Seems like Marshall is removing himself from reviewers here?
I can help review, but I can't guarantee my latency on turn around.
Kyösti Mälkki has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3:
Patch Set 3:
Not sure why you want to move code from a already existing file into a new file? Are you planning on doing this unification? What about future Agesa version 9 (currently being developed)? Should we force Agesa 9 to use this loaders? I would rather wait Martin's opinion.
You cannot talk to me about AGESAv9. Not my choice, I would like it if you could.
From I understood AGESAv9 is such a different beast that code-sharing with AGESAv8 in coreboot proper would not make sense. And for god's sake let's finally drop agesawrapper.c!
Richard Spiegel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3: Code-Review+1
(1 comment)
Patch Set 3:
Patch Set 3:
Not sure why you want to move code from a already existing file into a new file? Are you planning on doing this unification? What about future Agesa version 9 (currently being developed)? Should we force Agesa 9 to use this loaders? I would rather wait Martin's opinion.
You cannot talk to me about AGESAv9. Not my choice, I would like it if you could.
From I understood AGESAv9 is such a different beast that code-sharing with AGESAv8 in coreboot proper would not make sense. And for god's sake let's finally drop agesawrapper.c!
Marshall is the one involved with AGESA v9. I still don't like creating a separate file for just moving some functions, though if you really unify all code I'll accept it makes sense. Nothing to complain on the files themselves, just the copyright date on the new file.
https://review.coreboot.org/#/c/31318/3/src/soc/amd/common/block/pi/refcode_... File src/soc/amd/common/block/pi/refcode_loader.c:
https://review.coreboot.org/#/c/31318/3/src/soc/amd/common/block/pi/refcode_... PS3, Line 4: 2017 As this is a new file (though old code), maybe 2019?
Marshall Dawson has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3:
Martin, Aaron; Can you tell who is the person to do kahlee reviews? Seems like Marshall is removing himself from reviewers here?
Kyosti, I'm removing an email address I don't use and adding my normal marshalldawson3rd one instead.
Marshall Dawson has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
Patch Set 3: Code-Review+2
(1 comment)
I only gave a cursory glance at the new file. Those functions were copied verbatim, correct?
https://review.coreboot.org/#/c/31318/3/src/soc/amd/common/block/pi/refcode_... File src/soc/amd/common/block/pi/refcode_loader.c:
https://review.coreboot.org/#/c/31318/3/src/soc/amd/common/block/pi/refcode_... PS3, Line 4: 2017
As this is a new file (though old code), maybe 2019?
It's only moving source that was already copyrighted in 2017, not new source developed in 2019.
Kyösti Mälkki has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/31318 )
Change subject: soc/amd/common: Move PI refcode loader ......................................................................
soc/amd/common: Move PI refcode loader
The moved functions are only about locating and loading the refcode blobs. Separate them from the actual calls into the blob. Eventually previous binaryPI blobs should be unified to share same loader code.
Change-Id: I68885e7f855b195c178e746c8f3f0f49166d0def Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com Reviewed-on: https://review.coreboot.org/c/31318 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Richard Spiegel richard.spiegel@silverbackltd.com Reviewed-by: Marshall Dawson marshalldawson3rd@gmail.com --- M src/soc/amd/common/block/pi/Makefile.inc M src/soc/amd/common/block/pi/agesawrapper.c A src/soc/amd/common/block/pi/refcode_loader.c 3 files changed, 155 insertions(+), 136 deletions(-)
Approvals: build bot (Jenkins): Verified Marshall Dawson: Looks good to me, approved Richard Spiegel: Looks good to me, but someone else must approve
diff --git a/src/soc/amd/common/block/pi/Makefile.inc b/src/soc/amd/common/block/pi/Makefile.inc index ba08123..5afbb3e 100644 --- a/src/soc/amd/common/block/pi/Makefile.inc +++ b/src/soc/amd/common/block/pi/Makefile.inc @@ -4,6 +4,7 @@ romstage-y += def_callouts.c romstage-y += heapmanager.c romstage-y += image.c +romstage-y += refcode_loader.c
ramstage-y += agesawrapper.c ramstage-y += amd_late_init.c @@ -11,5 +12,6 @@ ramstage-y += def_callouts.c ramstage-y += heapmanager.c ramstage-y += image.c +ramstage-y += refcode_loader.c
endif diff --git a/src/soc/amd/common/block/pi/agesawrapper.c b/src/soc/amd/common/block/pi/agesawrapper.c index 89cb9be..92153ee 100644 --- a/src/soc/amd/common/block/pi/agesawrapper.c +++ b/src/soc/amd/common/block/pi/agesawrapper.c @@ -15,17 +15,12 @@ */
#include <arch/acpi.h> -#include <cpu/x86/mtrr.h> -#include <cbfs.h> #include <cbmem.h> #include <delay.h> -#include <rmodule.h> -#include <stage_cache.h> #include <string.h> #include <timestamp.h> #include <amdblocks/s3_resume.h> #include <amdblocks/agesawrapper.h> -#include <amdblocks/image.h> #include <amdblocks/BiosCallOuts.h> #include <soc/pci_devs.h> #include <soc/southbridge.h> @@ -498,134 +493,3 @@
return Status; } - -static int agesa_locate_file(const char *name, struct region_device *rdev, - uint32_t type) -{ - struct cbfsf fh; - - if (cbfs_boot_locate(&fh, name, &type)) - return -1; - - cbfs_file_data(rdev, &fh); - return 0; -} - -static int agesa_locate_raw_file(const char *name, struct region_device *rdev) -{ - return agesa_locate_file(name, rdev, CBFS_TYPE_RAW); -} - -static int agesa_locate_stage_file_early(const char *name, - struct region_device *rdev) -{ - const size_t metadata_sz = sizeof(struct cbfs_stage); - - if (agesa_locate_file(name, rdev, CBFS_TYPE_STAGE)) - return -1; - - /* Peel off the cbfs stage metadata. */ - return rdev_chain(rdev, rdev, metadata_sz, - region_device_sz(rdev) - metadata_sz); -} - -static int agesa_locate_stage_file_ramstage(const char *name, - struct region_device *rdev) -{ - struct prog prog = PROG_INIT(PROG_REFCODE, name); - struct rmod_stage_load rmod_agesa = { - .cbmem_id = CBMEM_ID_REFCODE, - .prog = &prog, - }; - - if (acpi_is_wakeup_s3() && !IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { - printk(BIOS_INFO, "AGESA: Loading stage from cache\n"); - // There is no way to tell if this succeeded. - stage_cache_load_stage(STAGE_REFCODE, &prog); - } else { - if (prog_locate(&prog)) - return -1; - - if (rmodule_stage_load(&rmod_agesa) < 0) - return -1; - - if (!IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { - printk(BIOS_INFO, "AGESA: Saving stage to cache\n"); - stage_cache_add(STAGE_REFCODE, &prog); - } - } - - return rdev_chain(rdev, prog_rdev(&prog), 0, - region_device_sz(prog_rdev(&prog))); -} - -static int agesa_locate_stage_file(const char *name, struct region_device *rdev) -{ - if (!ENV_RAMSTAGE || !IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) - return agesa_locate_stage_file_early(name, rdev); - return agesa_locate_stage_file_ramstage(name, rdev); -} - -static const char *get_agesa_cbfs_name(void) -{ - if (!IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) - return CONFIG_AGESA_CBFS_NAME; - if (!ENV_RAMSTAGE) - return CONFIG_AGESA_PRE_MEMORY_CBFS_NAME; - return CONFIG_AGESA_POST_MEMORY_CBFS_NAME; -} - -const void *agesawrapper_locate_module(const char name[8]) -{ - const void *agesa; - const AMD_IMAGE_HEADER *image; - struct region_device rdev; - size_t file_size; - const char *fname; - int ret; - - fname = get_agesa_cbfs_name(); - - if (IS_ENABLED(CONFIG_AGESA_BINARY_PI_AS_STAGE)) - ret = agesa_locate_stage_file(fname, &rdev); - else - ret = agesa_locate_raw_file(fname, &rdev); - - if (ret) - return NULL; - - file_size = region_device_sz(&rdev); - - /* Assume boot device is memory mapped so the mapping can leak. */ - assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED)); - - agesa = rdev_mmap_full(&rdev); - - if (!agesa) - return NULL; - - image = amd_find_image(agesa, agesa + file_size, 4096, name); - - if (!image) - return NULL; - - return (AMD_MODULE_HEADER *)image->ModuleInfoOffset; -} - -static MODULE_ENTRY agesa_dispatcher; - -MODULE_ENTRY agesa_get_dispatcher(void) -{ - const AMD_MODULE_HEADER *module; - static const char id[8] = AGESA_ID; - - if (agesa_dispatcher != NULL) - return agesa_dispatcher; - - module = agesawrapper_locate_module(id); - if (!module) - return NULL; - - agesa_dispatcher = module->ModuleDispatcher; - return agesa_dispatcher; -} diff --git a/src/soc/amd/common/block/pi/refcode_loader.c b/src/soc/amd/common/block/pi/refcode_loader.c new file mode 100644 index 0000000..7937817 --- /dev/null +++ b/src/soc/amd/common/block/pi/refcode_loader.c @@ -0,0 +1,153 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2012 - 2017 Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include <arch/acpi.h> +#include <cbfs.h> +#include <cbmem.h> +#include <rmodule.h> +#include <stage_cache.h> +#include <amdblocks/agesawrapper.h> +#include <amdblocks/image.h> + +static int agesa_locate_file(const char *name, struct region_device *rdev, + uint32_t type) +{ + struct cbfsf fh; + + if (cbfs_boot_locate(&fh, name, &type)) + return -1; + + cbfs_file_data(rdev, &fh); + return 0; +} + +static int agesa_locate_raw_file(const char *name, struct region_device *rdev) +{ + return agesa_locate_file(name, rdev, CBFS_TYPE_RAW); +} + +static int agesa_locate_stage_file_early(const char *name, + struct region_device *rdev) +{ + const size_t metadata_sz = sizeof(struct cbfs_stage); + + if (agesa_locate_file(name, rdev, CBFS_TYPE_STAGE)) + return -1; + + /* Peel off the cbfs stage metadata. */ + return rdev_chain(rdev, rdev, metadata_sz, + region_device_sz(rdev) - metadata_sz); +} + +static int agesa_locate_stage_file_ramstage(const char *name, + struct region_device *rdev) +{ + struct prog prog = PROG_INIT(PROG_REFCODE, name); + struct rmod_stage_load rmod_agesa = { + .cbmem_id = CBMEM_ID_REFCODE, + .prog = &prog, + }; + + if (acpi_is_wakeup_s3() && !IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { + printk(BIOS_INFO, "AGESA: Loading stage from cache\n"); + // There is no way to tell if this succeeded. + stage_cache_load_stage(STAGE_REFCODE, &prog); + } else { + if (prog_locate(&prog)) + return -1; + + if (rmodule_stage_load(&rmod_agesa) < 0) + return -1; + + if (!IS_ENABLED(CONFIG_NO_STAGE_CACHE)) { + printk(BIOS_INFO, "AGESA: Saving stage to cache\n"); + stage_cache_add(STAGE_REFCODE, &prog); + } + } + + return rdev_chain(rdev, prog_rdev(&prog), 0, + region_device_sz(prog_rdev(&prog))); +} + +static int agesa_locate_stage_file(const char *name, struct region_device *rdev) +{ + if (!ENV_RAMSTAGE || !IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) + return agesa_locate_stage_file_early(name, rdev); + return agesa_locate_stage_file_ramstage(name, rdev); +} + +static const char *get_agesa_cbfs_name(void) +{ + if (!IS_ENABLED(CONFIG_AGESA_SPLIT_MEMORY_FILES)) + return CONFIG_AGESA_CBFS_NAME; + if (!ENV_RAMSTAGE) + return CONFIG_AGESA_PRE_MEMORY_CBFS_NAME; + return CONFIG_AGESA_POST_MEMORY_CBFS_NAME; +} + +const void *agesawrapper_locate_module(const char name[8]) +{ + const void *agesa; + const AMD_IMAGE_HEADER *image; + struct region_device rdev; + size_t file_size; + const char *fname; + int ret; + + fname = get_agesa_cbfs_name(); + + if (IS_ENABLED(CONFIG_AGESA_BINARY_PI_AS_STAGE)) + ret = agesa_locate_stage_file(fname, &rdev); + else + ret = agesa_locate_raw_file(fname, &rdev); + + if (ret) + return NULL; + + file_size = region_device_sz(&rdev); + + /* Assume boot device is memory mapped so the mapping can leak. */ + assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED)); + + agesa = rdev_mmap_full(&rdev); + + if (!agesa) + return NULL; + + image = amd_find_image(agesa, agesa + file_size, 4096, name); + + if (!image) + return NULL; + + return (AMD_MODULE_HEADER *)image->ModuleInfoOffset; +} + +static MODULE_ENTRY agesa_dispatcher; + +MODULE_ENTRY agesa_get_dispatcher(void) +{ + const AMD_MODULE_HEADER *module; + static const char id[8] = AGESA_ID; + + if (agesa_dispatcher != NULL) + return agesa_dispatcher; + + module = agesawrapper_locate_module(id); + if (!module) + return NULL; + + agesa_dispatcher = module->ModuleDispatcher; + return agesa_dispatcher; +}