cbfs: Replace more instances of cbfs_boot_locate() with newer APIs

In pursuit of the eventual goal of removing cbfs_boot_locate() (and
direct rdev access) from CBFS APIs, this patch replaces all remaining
"simple" uses of the function call that can easily be replaced by the
newer APIs (like cbfs_load() or cbfs_map()). Some cases of
cbfs_boot_locate() remain that will be more complicated to solve.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Icd0f21e2fa49c7cc834523578b7b45b5482cb1a8
Reviewed-on: https://review.coreboot.org/c/coreboot/+/50348
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/src/security/intel/txt/common.c b/src/security/intel/txt/common.c
index 4dd4ad3..437c55e 100644
--- a/src/security/intel/txt/common.c
+++ b/src/security/intel/txt/common.c
@@ -215,25 +215,17 @@
  */
 static void *intel_txt_prepare_bios_acm(struct region_device *acm, size_t *acm_len)
 {
-	struct cbfsf file;
 	void *acm_data = NULL;
 
 	if (!acm || !acm_len)
 		return NULL;
 
-	if (cbfs_boot_locate(&file, CONFIG_INTEL_TXT_CBFS_BIOS_ACM, NULL)) {
+	acm_data = cbfs_map(CONFIG_INTEL_TXT_CBFS_BIOS_ACM, acm_len);
+	if (!acm_data) {
 		printk(BIOS_ERR, "TEE-TXT: Couldn't locate BIOS ACM in CBFS.\n");
 		return NULL;
 	}
 
-	cbfs_file_data(acm, &file);
-	acm_data = rdev_mmap_full(acm);
-	*acm_len = region_device_sz(acm);
-	if (!acm_data || *acm_len == 0) {
-		printk(BIOS_ERR, "TEE-TXT: Couldn't map BIOS ACM from CBFS.\n");
-		return NULL;
-	}
-
 	/*
 	 * CPU enforces only 4KiB alignment.
 	 * Chapter A.1.1
@@ -241,7 +233,7 @@
 	 */
 	if (!IS_ALIGNED((uintptr_t)acm_data, 4096)) {
 		printk(BIOS_ERR, "TEE-TXT: BIOS ACM isn't mapped at page boundary.\n");
-		rdev_munmap(acm, acm_data);
+		cbfs_unmap(acm_data);
 		return NULL;
 	}
 
@@ -252,7 +244,7 @@
 	 */
 	if (!IS_ALIGNED(*acm_len, 64)) {
 		printk(BIOS_ERR, "TEE-TXT: BIOS ACM size isn't multiple of 64.\n");
-		rdev_munmap(acm, acm_data);
+		cbfs_unmap(acm_data);
 		return NULL;
 	}
 
@@ -262,7 +254,7 @@
 	 */
 	if (!IS_ALIGNED((uintptr_t)acm_data, (1UL << log2_ceil(*acm_len)))) {
 		printk(BIOS_ERR, "TEE-TXT: BIOS ACM isn't aligned to its size.\n");
-		rdev_munmap(acm, acm_data);
+		cbfs_unmap(acm_data);
 		return NULL;
 	}
 
@@ -273,7 +265,7 @@
 	 */
 	if (popcnt(ALIGN_UP(*acm_len, 4096)) > get_var_mtrr_count()) {
 		printk(BIOS_ERR, "TEE-TXT: Not enough MTRRs to cache this BIOS ACM's size.\n");
-		rdev_munmap(acm, acm_data);
+		cbfs_unmap(acm_data);
 		return NULL;
 	}
 
@@ -283,7 +275,7 @@
 	const int ret = validate_acm(acm_data);
 	if (ret < 0) {
 		printk(BIOS_ERR, "TEE-TXT: Validation of ACM failed with: %d\n", ret);
-		rdev_munmap(acm, acm_data);
+		cbfs_unmap(acm_data);
 		return NULL;
 	}